source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/duration.rb | Ruby | mit | 47 | main | 846 | # frozen_string_literal: true
require 'kdl/types/duration/iso8601_parser'
module KDL
module Types
class Duration < Value::Custom
attr_reader :years, :months, :weeks, :days, :hours, :minutes, :seconds
def initialize(parts = {}, format: nil, type: 'duration')
super
@years = parts.fetc... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/url_template.rb | Ruby | mit | 47 | main | 8,071 | # frozen_string_literal: true
require 'uri'
module KDL
module Types
class URLTemplate < Value::Custom
UNRESERVED = /[a-zA-Z0-9\-._~]/.freeze
RESERVED = %r{[:/?#\[\]@!$&'()*+,;=]}.freeze
def self.call(value, type = 'url-template')
return nil unless value.is_a? ::KDL::Value::String
... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/regex.rb | Ruby | mit | 47 | main | 322 | # frozen_string_literal: true
module KDL
module Types
class Regex < Value::Custom
def self.call(value, type = 'regex')
return nil unless value.is_a? ::KDL::Value::String
regex = ::Regexp.new(value.value)
new(regex, type: type)
end
end
MAPPING['regex'] = Regex
end
en... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/base64.rb | Ruby | mit | 47 | main | 506 | # frozen_string_literal: true
require 'base64'
module KDL
module Types
class Base64 < Value::Custom
RGX = /^[A-Za-z0-9+\/=]+$/.freeze
def self.call(value, type = 'base64')
return nil unless value.is_a? ::KDL::Value::String
unless RGX.match?(value.value)
raise ArgumentEr... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/country.rb | Ruby | mit | 47 | main | 2,133 | # frozen_string_literal: true
require 'kdl/types/country/iso3166_countries'
require 'kdl/types/country/iso3166_subdivisions'
module KDL
module Types
class Country < Value::Custom
attr_reader :name, :alpha2, :alpha3, :numeric_code
def initialize(value, format: nil, type: 'country-3')
super
... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/email.rb | Ruby | mit | 47 | main | 1,214 | # frozen_string_literal: true
require_relative './email/parser'
module KDL
module Types
class Email < Value::Custom
attr_reader :local, :domain
def initialize(value, local:, domain:, **kwargs)
super(value, **kwargs)
@local = local
@domain = domain
end
def self.c... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/irl.rb | Ruby | mit | 47 | main | 1,248 | # frozen_string_literal: true
require_relative './irl/parser'
module KDL
module Types
class IRLReference < Value::Custom
attr_reader :unicode_value,
:unicode_domain,
:unicode_path,
:unicode_search,
:unicode_hash
def initialize(... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/ip.rb | Ruby | mit | 47 | main | 648 | # frozen_string_literal: true
module KDL
module Types
class IP < Value::Custom
def self.call(value, type = ip_type)
return nil unless value.is_a? ::KDL::Value::String
ip = ::IPAddr.new(value.value)
raise ArgumentError, "invalid #{ip_type} address" unless valid_ip?(ip)
new(... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/hostname.rb | Ruby | mit | 47 | main | 1,045 | # frozen_string_literal: true
require_relative './hostname/validator'
module KDL
module Types
class Hostname < Value::Custom
def self.call(value, type = 'hostname')
return nil unless value.is_a? ::KDL::Value::String
validator = Validator.new(value.value)
raise ArgumentError, "inva... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/currency.rb | Ruby | mit | 47 | main | 734 | # frozen_string_literal: true
require 'kdl/types/currency/iso4217_currencies'
module KDL
module Types
class Currency < Value::Custom
attr_reader :numeric_code, :minor_unit, :name
def initialize(value, format: nil, type: 'currency')
super
@numeric = value.fetch(:numeric, nil)
... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/url.rb | Ruby | mit | 47 | main | 688 | # frozen_string_literal: true
module KDL
module Types
class URLReference < Value::Custom
def self.call(value, type = 'url-reference')
return nil unless value.is_a? ::KDL::Value::String
uri = parse_url(value.value)
new(uri, type: type)
end
def self.parse_url(string)
... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/decimal.rb | Ruby | mit | 47 | main | 340 | # frozen_string_literal: true
module KDL
module Types
class Decimal < Value::Custom
def self.call(value, type = 'decimal')
return nil unless value.is_a? ::KDL::Value::String
big_decimal = BigDecimal(value.value)
new(big_decimal, type: type)
end
end
MAPPING['decimal'] ... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/currency/iso4217_currencies.rb | Ruby | mit | 47 | main | 16,389 | # frozen_string_literal: true
module KDL
module Types
class Currency < Value::Custom
# From https://en.wikipedia.org/wiki/ISO_4217#Active_codes
CURRENCIES = {
'AED' => { numeric_code: 784, minor_unit: 2, name: 'United Arab Emirates dirham' }.freeze,
'AFN' => { numeric_code: 971, minor... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/country/iso3166_countries.rb | Ruby | mit | 47 | main | 33,234 | # frozen_string_literal: true
module KDL
module Types
class Country < Value::Custom
# From: https://en.wikipedia.org/wiki/ISO_3166-1#Current_codes
COUNTRIES3 = {
'AFG' => { alpha3: 'AFG', alpha2: 'AF', numeric_code: 4, name: 'Afghanistan' }.freeze,
'ALA' => { alpha3: 'ALA', alpha2: 'A... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/country/iso3166_subdivisions.rb | Ruby | mit | 47 | main | 131,957 | # frozen_string_literal: true
module KDL
module Types
class CountrySubdivision < Value::Custom
# From: https://en.wikipedia.org/wiki/ISO_3166-2#Current_codes
COUNTRY_SUBDIVISIONS = {
"AD" => {
"AD-07" => "Andorra la Vella",
"AD-02" => "Canillo",
"AD-03" => "Encam... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/irl/parser.rb | Ruby | mit | 47 | main | 3,982 | # frozen_string_literal: true
module KDL
module Types
class IRLReference < Value::Custom
class Parser
RGX = /^(?:(?:([a-z][a-z0-9+.\-]+)):\/\/([^@]+@)?([^\/?#]+)?)?(\/?[^?#]*)?(?:\?([^#]*))?(?:#(.*))?$/i.freeze
PERCENT_RGX = /%[a-f0-9]{2}/i.freeze
RESERVED_URL_CHARS = %w[! # $ & ' ... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/duration/iso8601_parser.rb | Ruby | mit | 47 | main | 4,873 | # frozen_string_literal: true
# Shamelessly borrowed from https://github.com/rails/rails/tree/main/activesupport
#
# Copyright (c) 2005-2021 David Heinemeier Hansson
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"),... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/email/parser.rb | Ruby | mit | 47 | main | 4,454 | # frozen_string_literal: true
require_relative '../hostname/validator'
module KDL
module Types
class Email < Value::Custom
class Parser
def initialize(string, idn: false)
@string = string
@idn = idn
@tokenizer = Tokenizer.new(string, idn: idn)
end
def... |
github | danini-the-panini/kdl-rb | https://github.com/danini-the-panini/kdl-rb | lib/kdl/types/hostname/validator.rb | Ruby | mit | 47 | main | 1,152 | # frozen_string_literal: true
require 'simpleidn'
module KDL
module Types
class Hostname < Value::Custom
class Validator
PART_RGX = /^[a-z0-9_][a-z0-9_\-]{0,62}$/i
attr_reader :string
alias ascii string
alias unicode string
def initialize(string)
@string... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | Rakefile | Ruby | mit | 47 | master | 1,121 | require 'rake'
require 'spec/rake/spectask'
require 'rake/rdoctask'
desc "Default: run specs"
task :default => :spec
desc "Run all the specs for the notamock plugin."
Spec::Rake::SpecTask.new do |t|
t.spec_files = FileList['spec/**/*_spec.rb']
t.spec_opts = ['--colour']
t.rcov = true
end
desc "Generate documen... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | lib/not_a_mock.rb | Ruby | mit | 47 | master | 574 | require 'not_a_mock/active_record_extensions'
require 'not_a_mock/argument_constraint_extensions'
require 'not_a_mock/call_recorder'
require 'not_a_mock/matchers'
require 'not_a_mock/matchers/anything_matcher'
require 'not_a_mock/matchers/args_matcher'
require 'not_a_mock/matchers/call_matcher'
require 'not_a_mock/matc... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | lib/not_a_mock/active_record_extensions.rb | Ruby | mit | 47 | master | 311 | module ActiveRecord # :nodoc:
class Base
def self.stub_instance(methods = {})
@@__stub_object_id ||= 1000
@@__stub_object_id += 1
methods = methods.merge(:id => @@__stub_object_id, :to_param => @@__stub_object_id.to_s)
NotAMock::Stub.new(self, methods)
end
end
end |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | lib/not_a_mock/matchers.rb | Ruby | mit | 47 | master | 2,306 | module NotAMock
# == Message Assertions
#
# You can assert that an object should have received particular messages:
#
# object.should have_received(:message)
# object.should_not have_received(:message)
#
# Further restrictions cannot be added after +should_not have_received+.
#
# You can als... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | lib/not_a_mock/rspec_mock_framework_adapter.rb | Ruby | mit | 47 | master | 282 | module NotAMock
module RspecMockFrameworkAdapter
def setup_mocks_for_rspec
end
def verify_mocks_for_rspec
end
def teardown_mocks_for_rspec
NotAMock::CallRecorder.instance.reset
NotAMock::Stubber.instance.reset
end
end
end |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | lib/not_a_mock/argument_constraint_extensions.rb | Ruby | mit | 47 | master | 578 | require 'set'
module Spec #:nodoc:
module Mocks #:nodoc:
class AnyOrderArgConstraint #:nodoc:
def initialize(array)
@array = array
end
def ==(arg)
Set.new(@array) == Set.new(arg)
end
def inspect
"in_any_order(#{@array.inspect})"
end
... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | lib/not_a_mock/stub.rb | Ruby | mit | 47 | master | 1,040 | module NotAMock
# Instances returned by Object.stub_instance are NotAMock::Stub objects.
# These do their best to masquerade as the real thing.
class Stub
# This is normall only called from Object.stub_instance.
def initialize(stubbed_class, methods = {}) #:nodoc:
@stubbed_class = stubbed_class... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | lib/not_a_mock/call_recorder.rb | Ruby | mit | 47 | master | 2,729 | require 'singleton'
require 'not_a_mock/object_extensions'
module NotAMock
# The CallRecorder is a singleton that keeps track of all the call
# recording hooks installed, and keeps a central record of calls.
class CallRecorder
include Singleton
def initialize
@calls = []
@tracked_methods =... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | lib/not_a_mock/stubber.rb | Ruby | mit | 47 | master | 1,949 | require 'singleton'
require 'not_a_mock/object_extensions'
module NotAMock
# The Stubber is a singleton that keeps track of all the stub methods
# installed in any object.
class Stubber
include Singleton
def initialize
@stubbed_methods = []
end
# Stub +method+ on +object+ to evalutate... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | lib/not_a_mock/object_extensions.rb | Ruby | mit | 47 | master | 3,625 | class Object
# Call this on any object or class with a list of method names. Any future
# calls to those methods will be recorded in NotAMock::CallRecorder.
#
# See NotAMock::Matchers for info on how to test which methods have been
# called, with what arguments, etc.
def track_methods(*methods)
if me... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | lib/not_a_mock/matchers/call_matcher.rb | Ruby | mit | 47 | master | 1,268 | module NotAMock
module Matchers
class CallMatcher
def initialize(parent = nil)
@parent = parent
end
def matches?(object)
@object = object
@matched = parent_matches? && matches_without_parents?
end
def matched?; @matched end
attr_reader :c... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | lib/not_a_mock/matchers/result_matcher.rb | Ruby | mit | 47 | master | 626 | require 'not_a_mock/matchers/call_matcher'
module NotAMock
module Matchers
# Matcher for
# and_returned(...)
class ResultMatcher < CallMatcher
def initialize(result, parent = nil)
super parent
@result = result
end
def matches_without_parents?
@calls = @pa... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | lib/not_a_mock/matchers/anything_matcher.rb | Ruby | mit | 47 | master | 554 | require 'not_a_mock/matchers/call_matcher'
module NotAMock
module Matchers
# Matcher for
# object.should have_been_called
class AnythingMatcher < CallMatcher
def initialize(parent = nil)
super parent
end
def matches_without_parents?
@calls = CallRecorder.instance... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | lib/not_a_mock/matchers/method_matcher.rb | Ruby | mit | 47 | master | 625 | require 'not_a_mock/matchers/call_matcher'
module NotAMock
module Matchers
# Matcher for
# object.should have_received(...)
class MethodMatcher < CallMatcher
def initialize(method, parent = nil)
super parent
@method = method
end
def matches_without_parents?
... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | lib/not_a_mock/matchers/args_matcher.rb | Ruby | mit | 47 | master | 1,794 | require 'not_a_mock/matchers/call_matcher'
module NotAMock
module Matchers
# Matcher for
# with(...)
#
# == Argument Matchers
#
# Not A Mock supports the use of RSpec's patterns for argument matching
# in mocks, and extends them. The most useful are listed below.
#
# === Anything... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | lib/not_a_mock/matchers/times_matcher.rb | Ruby | mit | 47 | master | 917 | require 'not_a_mock/matchers/call_matcher'
module NotAMock
module Matchers
# Matcher for +once+, +twice+, and
# exactly(n).times
class TimesMatcher < CallMatcher
def initialize(times, parent = nil)
super parent
@times = times
end
def matches_without_parents?
... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | spec/stub_instance_spec.rb | Ruby | mit | 47 | master | 1,332 | $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
require 'not_a_mock'
describe "A stub instance" do
before do
@object = String.stub_instance(:length => 42, :id => 99)
end
it "should return the right result for a stubbed method" do
@object.length.should == 42
end
it "should return its na... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | spec/stub_active_record_spec.rb | Ruby | mit | 47 | master | 746 | $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
require 'not_a_mock'
class ExampleActiveRecord < ActiveRecord::Base
end
describe "A stubbed ActiveRecord object" do
before do
@example = ExampleActiveRecord.stub_instance
end
it "should return a valid id" do
lambda { @example.id }.should_not ra... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | spec/call_recording_spec.rb | Ruby | mit | 47 | master | 2,461 | $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
require 'not_a_mock'
class TrackedClass
def my_method(argument)
"result"
end
end
describe "A recorded method" do
before do
@recorder = NotAMock::CallRecorder.instance
@object = TrackedClass.new
@object.track_method(:my_method)
end
i... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | spec/stub_method_spec.rb | Ruby | mit | 47 | master | 5,814 | $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
require 'not_a_mock'
describe "A stubbed method replacing an existing instance method" do
before do
@object = "Hello, world!"
@object.stub_method(:length => 42)
end
it "should return the stubbed result" do
@object.length.should == 42
end
... |
github | notahat/not_a_mock | https://github.com/notahat/not_a_mock | spec/matchers_spec.rb | Ruby | mit | 47 | master | 7,145 | $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
require 'not_a_mock'
class TrackedClass < Object
def initialize(*calls)
calls.each do |call|
NotAMock::CallRecorder.instance.calls << call.merge(:object => self)
end
end
def inspect
"TrackedClass"
end
end
describe NotAMock::Matchers::A... |
github | edavis10/kindle | https://github.com/edavis10/kindle | bin/notes_for_book.rb | Ruby | mit | 47 | master | 543 | #!/usr/bin/env ruby
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'kindle'
unless ARGV[0] && File.exists?(ARGV[0])
puts "ERROR: need file"
exit(-1)
end
unless ARGV[1]
puts "ERROR: need a book name"
exit(-1)
end
search_for = Regexp.new(Regexp.escape(Regexp.escape(ARGV[1])), Regexp::IGNORE... |
github | edavis10/kindle | https://github.com/edavis10/kindle | bin/setup_couch.rb | Ruby | mit | 47 | master | 386 | #!/usr/bin/env ruby
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'kindle'
require 'kindle/couch'
views = {
"_id" => "_design/books",
"language" => 'javascript',
"views" =>
{
"list" => {
"map" => 'function(doc) { emit(doc._id, doc.title); }',
}
}
}
system("curl -X PUT 'http... |
github | edavis10/kindle | https://github.com/edavis10/kindle | bin/import_into_couchdb.rb | Ruby | mit | 47 | master | 280 | #!/usr/bin/env ruby
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'kindle'
require 'kindle/couch'
unless ARGV[0] && File.exists?(ARGV[0])
puts "ERROR: need file"
exit(-1)
end
Kindle::File.parse_books(ARGV[0]).each do |book|
Kindle::Couch.add(book)
end |
github | edavis10/kindle | https://github.com/edavis10/kindle | bin/to_orgmode.rb | Ruby | mit | 47 | master | 474 | #!/usr/bin/env ruby
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'kindle'
require "kindle/org_mode"
require 'fileutils'
unless ARGV[0] && File.exists?(ARGV[0])
puts "ERROR: need kindle notes file"
exit(-1)
end
unless ARGV[1]
puts "ERROR: need destination directory"
exit(-1)
end
destinati... |
github | edavis10/kindle | https://github.com/edavis10/kindle | bin/list_books.rb | Ruby | mit | 47 | master | 305 | #!/usr/bin/env ruby
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'kindle'
unless ARGV[0] && File.exists?(ARGV[0])
puts "ERROR: need file"
exit(-1)
end
Kindle::File.open(ARGV[0]).parse.books.sort.each do |book|
puts book.title
puts "- #{book.notes.length} notes"
puts
end |
github | edavis10/kindle | https://github.com/edavis10/kindle | bin/to_markdown.rb | Ruby | mit | 47 | master | 475 | #!/usr/bin/env ruby
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'kindle'
require "kindle/markdown"
require 'fileutils'
unless ARGV[0] && File.exists?(ARGV[0])
puts "ERROR: need kindle notes file"
exit(-1)
end
unless ARGV[1]
puts "ERROR: need destination directory"
exit(-1)
end
destinati... |
github | edavis10/kindle | https://github.com/edavis10/kindle | lib/kindle/org_mode.rb | Ruby | mit | 47 | master | 519 | module Kindle
class OrgMode
def self.save(book, path)
filename = path + "/" + book.to_file_name + ".org"
::File.open(filename, 'w') do |file|
file.puts("* #{book.title}\n\n")
file.puts("Author: #{book.author}")
file.puts("Last updated: #{book.last_updated}")
file.puts(... |
github | edavis10/kindle | https://github.com/edavis10/kindle | lib/kindle/note.rb | Ruby | mit | 47 | master | 929 | require 'rubygems'
require 'chronic'
module Kindle
class Note
attr_accessor :content
attr_accessor :location
attr_accessor :added
def content
(@content || '').strip
end
def self.from_kindle_format(raw_note)
title_author, highlight, *notes = *raw_note.split("\r\n")
n... |
github | edavis10/kindle | https://github.com/edavis10/kindle | lib/kindle/couch.rb | Ruby | mit | 47 | master | 622 | require 'rubygems'
require 'couchrest'
module Kindle
class Couch
def self.add(book)
if record = get(book) # update
database.save_doc(book.to_document.merge('_rev' => record['_rev']))
else
database.save_doc(book.to_document)
end
end
def self.get(book)
begin
... |
github | edavis10/kindle | https://github.com/edavis10/kindle | lib/kindle/book_author.rb | Ruby | mit | 47 | master | 372 | module Kindle
class BookAuthor
def self.from_kindle_format(note)
title_author, *notes = *note.split("\r\n")
# "Title (something optional) (Author)" =>
# "Author"
author_match = title_author.match(/\(([^()]*)\)$/)
if author_match
author = author_match[1]
else
a... |
github | edavis10/kindle | https://github.com/edavis10/kindle | lib/kindle/book_title.rb | Ruby | mit | 47 | master | 389 | module Kindle
class BookTitle
def self.from_kindle_format(note)
title_author, *notes = *note.split("\r\n")
# "Title (something optional) (Author)" =>
# "Title (somethine optional)"
title_match = title_author.match(/(.*)\(.*\)$/)
if title_match
title = title_match[1].strip
... |
github | edavis10/kindle | https://github.com/edavis10/kindle | lib/kindle/book.rb | Ruby | mit | 47 | master | 1,202 | module Kindle
class Book
include Enumerable
attr_accessor :title
attr_accessor :raw_notes
attr_accessor :author
def to_s
"<Kindle::Book title=#{@title} >"
end
def <=>(v)
self.title <=> v.title
end
def notes
raw_notes.sort
end
def last_updated
... |
github | edavis10/kindle | https://github.com/edavis10/kindle | lib/kindle/file.rb | Ruby | mit | 47 | master | 620 | module Kindle
class File
attr_accessor :data
attr_accessor :books
def self.open(file)
kindle_file = new
kindle_file.data = ::File.read(file)
kindle_file
end
def self.parse_books(file)
open(file).parse.books.sort
end
def parse
# Tmp data
books = {}... |
github | edavis10/kindle | https://github.com/edavis10/kindle | lib/kindle/markdown.rb | Ruby | mit | 47 | master | 506 | module Kindle
class Markdown
def self.save(book, path)
filename = path + "/" + book.to_file_name + ".md"
::File.open(filename, 'w') do |file|
file.puts("# #{book.title}\n\n")
file.puts("Author: #{book.author}")
file.puts("Last updated: #{book.last_updated}")
file.puts(... |
github | bfoz/geometry | https://github.com/bfoz/geometry | Rakefile | Ruby | bsd-2-clause | 47 | main | 594 | require "bundler/gem_tasks"
require 'rake/testtask'
task :default => :test
Rake::TestTask.new do |t|
t.libs.push "lib"
t.test_files = FileList['test/**/*.rb']
t.verbose = true
end
task :fixdates do
branch = `git branch --no-color -r --merged`.strip
`git fix-dates #{branch}..HEAD`
end
task :fixda... |
github | bfoz/geometry | https://github.com/bfoz/geometry | geometry.gemspec | Ruby | bsd-2-clause | 47 | main | 837 | # -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
Gem::Specification.new do |s|
spec = s
s.name = "geometry"
spec.version = '6.6'
s.authors = ["Brandon Fosdick"]
s.email = ["bfoz@bfoz.net"]
s.homepage = "http://github.com/bfoz/geometry"
s.summary = %q{Geom... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry.rb | Ruby | bsd-2-clause | 47 | main | 712 | require_relative 'geometry/annulus'
require_relative 'geometry/arc'
require_relative 'geometry/circle'
require_relative 'geometry/line'
require_relative 'geometry/obround'
require_relative 'geometry/path'
require_relative 'geometry/point'
require_relative 'geometry/point_zero'
require_relative 'geometry/polygon'
requir... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/annulus.rb | Ruby | bsd-2-clause | 47 | main | 3,013 | module Geometry
=begin rdoc
An {http://en.wikipedia.org/wiki/Annulus_(mathematics) Annulus}, more commonly
known as a Ring, is a circle that ate another circle.
== Usage
ring = Geometry::Annulus.new center:[1,2], inner_radius:5, radius:10
ring = Geometry::Ring.new center:[1,2], inner_radius:5, radius:10
=end... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/point_one.rb | Ruby | bsd-2-clause | 47 | main | 3,728 | module Geometry
=begin rdoc
An object repesenting a {Point} that is one unit away from the origin, along each
axis, in N-dimensional space
A {PointOne} object is a {Point} that will always compare equal to one and unequal to
everything else, regardless of size. It's similar to the
{http://en.wikipedia.org/wiki/Null_Ob... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/polyline.rb | Ruby | bsd-2-clause | 47 | main | 13,710 | require_relative 'edge'
module Geometry
=begin rdoc
A {Polyline} is like a {Polygon} in that it only contains straight lines, but
also like a {Path} in that it isn't necessarily closed.
{http://en.wikipedia.org/wiki/Polyline}
== Usage
=end
class Polyline
attr_reader :edges, :vertices
# @!attribute points
... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/size_zero.rb | Ruby | bsd-2-clause | 47 | main | 1,430 | require_relative 'point'
module Geometry
=begin rdoc
An object repesenting a zero {Size} in N-dimensional space
A {SizeZero} object is a {Size} that will always compare equal to zero and unequal to
everything else, regardless of dimensionality. You can think of it as an application of the
{http://en.wikipedia.org/wik... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/line.rb | Ruby | bsd-2-clause | 47 | main | 8,172 | require_relative 'cluster_factory'
require_relative 'point'
module Geometry
=begin rdoc
A cluster of objects representing a Line of infinite length
Supports two-point, slope-intercept, and point-slope initializer forms
== Usage
=== Two-point constructors
line = Geometry::Line[[0,0], [10,10]]
line = Geometr... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/arc.rb | Ruby | bsd-2-clause | 47 | main | 5,093 | require_relative 'point'
require_relative 'cluster_factory'
require_relative 'point'
module Geometry
=begin rdoc
{http://en.wikipedia.org/wiki/Arc_(geometry) Arcs} are Circles that don't quite go all the way around
== Usage
An {Arc} with its center at [1,1] and a radius of 2 that starts at the X-axis and goes to th... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/path.rb | Ruby | bsd-2-clause | 47 | main | 2,534 | require 'geometry/arc'
require 'geometry/edge'
module Geometry
=begin
An object representing a set of connected elements, each of which could be an
{Edge} or an {Arc}. Unlike a {Polygon}, a {Path} is not guaranteed to be closed.
=end
class Path
attr_reader :elements
# Construct a new Path from {Point}s, {Edge}s... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/polygon.rb | Ruby | bsd-2-clause | 47 | main | 12,883 | require_relative 'edge'
require_relative 'polyline'
module Geometry
=begin rdoc
A {Polygon} is a closed path comprised entirely of lines so straight they don't even curve.
{http://en.wikipedia.org/wiki/Polygon}
The {Polygon} class is generally intended to represent {http://en.wikipedia.org/wiki/Simple_polygon Simpl... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/circle.rb | Ruby | bsd-2-clause | 47 | main | 3,496 | require_relative 'cluster_factory'
require_relative 'point'
module Geometry
=begin rdoc
Circles come in all shapes and sizes, but they're usually round.
== Usage
circle = Geometry::Circle.new [1,2], 3
circle = Geometry::Circle.new center:[1,2], radius:3
circle = Geometry::Circle.new center:[1,2], diamete... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/regular_polygon.rb | Ruby | bsd-2-clause | 47 | main | 5,063 | require_relative 'polygon'
module Geometry
=begin rdoc
A {RegularPolygon} is a lot like a {Polygon}, but more regular.
{http://en.wikipedia.org/wiki/Regular_polygon}
== Usage
polygon = Geometry::RegularPolygon.new sides:4, center:[1,2], radius:3
polygon = Geometry::RegularPolygon.new sides:6, center:[1,2], d... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/vector.rb | Ruby | bsd-2-clause | 47 | main | 849 | require 'matrix'
# Monkeypatch Vector to overcome some deficiencies
class Vector
X = Vector[1,0,0]
Y = Vector[0,1,0]
Z = Vector[0,0,1]
# @group Unary operators
def +@
self
end
def -@
Vector[*(@elements.map {|e| -e })]
end
# @endgroup
# Cross-product of two {Vector}s
# @return [... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/point_iso.rb | Ruby | bsd-2-clause | 47 | main | 3,761 | module Geometry
=begin rdoc
An object repesenting a N-dimensional {Point} with identical elements.
=end
class PointIso
# @!attribute value
# @return [Number] the value for every element
attr_accessor :value
# Initialize to the given value
# @param value [Number] the value for every element of the new {Poin... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/obround.rb | Ruby | bsd-2-clause | 47 | main | 6,763 | require_relative 'cluster_factory'
require_relative 'point'
module Geometry
=begin
The {Obround} class cluster represents a rectangle with semicircular end caps
{http://en.wiktionary.org/wiki/obround}
=end
class Obround
include ClusterFactory
# @overload new(width, height)
# Creates a {Obround} of the giv... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/size_one.rb | Ruby | bsd-2-clause | 47 | main | 1,582 | require_relative 'point'
module Geometry
=begin rdoc
An object repesenting a {Size} of 1, in N-dimensional space
A {SizeOne} object is a {Size} that will always compare equal to one and unequal to
everything else, regardless of dimensionality. It's similar to the
{http://en.wikipedia.org/wiki/Null_Object_pattern Null... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/size.rb | Ruby | bsd-2-clause | 47 | main | 4,570 | require 'matrix'
require_relative 'size_one'
require_relative 'size_zero'
module Geometry
=begin
An object representing the size of something.
Supports all of the familiar {Vector} methods as well as a few convenience
methods (width, height and depth).
== Usage
=== Constructor
size = Geometry::Size[x,y,z]
=... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/bezier.rb | Ruby | bsd-2-clause | 47 | main | 1,144 | module Geometry
=begin
Bézier curves are like lines, but curvier.
http://en.wikipedia.org/wiki/Bézier_curve
== Constructors
Bezier.new [0,0], [1,1], [2,2] # From control points
== Usage
To get a point on the curve for a particular value of t, you can use the subscript operator
bezier[0.5] # => [1,1]
=end... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/rotation.rb | Ruby | bsd-2-clause | 47 | main | 5,396 | require 'matrix'
require_relative 'cluster_factory'
require_relative 'point'
module Geometry
=begin
A generalized representation of a rotation transformation.
== Usage
Rotation.new angle:45*Math.PI/180 # Rotate 45 degrees counterclockwise
Rotation.new x:[0,1] # Rotate 90 degrees counterclockwise
=end
cl... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/triangle.rb | Ruby | bsd-2-clause | 47 | main | 3,170 | require_relative 'cluster_factory'
require_relative 'point'
module Geometry
=begin rdoc
A {http://en.wikipedia.org/wiki/Triangle Triangle} is not a square.
== Usage
A right {Triangle} with its right angle at the origin and sides of length 1
triangle = Geometry::Triangle.new [0,0], [1,0], [0,1]
An isoscoles right... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/point_zero.rb | Ruby | bsd-2-clause | 47 | main | 3,548 | require_relative 'point_iso'
module Geometry
=begin rdoc
An object repesenting a {Point} at the origin in N-dimensional space
A {PointZero} object is a {Point} that will always compare equal to zero and unequal to
everything else, regardless of size. You can think of it as an application of the
{http://en.wikipedia.o... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/cluster_factory.rb | Ruby | bsd-2-clause | 47 | main | 302 | # Include this module in the base class of a class cluster to handle swizzling
# of ::new
module ClusterFactory
def self.included(parent)
class << parent
alias :original_new :new
def inherited(subclass)
class << subclass
alias :new :original_new
end
end
end
end
end |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/transformation.rb | Ruby | bsd-2-clause | 47 | main | 7,078 | require 'geometry/point'
require 'geometry/rotation'
require_relative 'transformation/composition'
module Geometry
=begin
{Transformation} represents a relationship between two coordinate frames.
To create a pure translation relationship:
translate = Geometry::Transformation.new(:translate => Point[4, 2])
To c... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/rectangle.rb | Ruby | bsd-2-clause | 47 | main | 11,940 | require_relative 'cluster_factory'
require_relative 'edge'
require_relative 'point'
require_relative 'point_zero'
require_relative 'size'
module Geometry
=begin
The {Rectangle} class cluster represents your typical arrangement of 4 corners and 4 sides.
== Usage
=== Constructors
rect = Rectangle.new [1,2], [2,3] ... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/edge.rb | Ruby | bsd-2-clause | 47 | main | 5,015 | require_relative 'point'
module Geometry
=begin rdoc
An edge. It's a line segment between 2 points. Generally part of a {Polygon}.
== Usage
edge = Geometry::Edge.new([1,1], [2,2])
edge = Geometry::Edge([1,1], [2,2])
=end
class Edge
attr_reader :first, :last
# Construct a new {Edge} object from any tw... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/point.rb | Ruby | bsd-2-clause | 47 | main | 8,617 | require 'matrix'
require_relative 'point_iso'
require_relative 'point_one'
require_relative 'point_zero'
module Geometry
DimensionMismatch = Class.new(StandardError)
OperationNotDefined = Class.new(StandardError)
=begin rdoc
An object repesenting a Point in N-dimensional space
Supports all of the familiar V... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/square.rb | Ruby | bsd-2-clause | 47 | main | 6,491 | require_relative 'point'
module Geometry
NotSquareError = Class.new(ArgumentError)
=begin
The {Square} class cluster is like the {Rectangle} class cluster, but not longer in one direction.
== Constructors
Square.new from:[1,2], to:[2,3] # Using two corners
Square.new origin:[3,4], size:5 # Using an orig... |
github | bfoz/geometry | https://github.com/bfoz/geometry | lib/geometry/transformation/composition.rb | Ruby | bsd-2-clause | 47 | main | 966 | module Geometry
class Transformation
class Composition
attr_reader :transformations
def initialize(*args)
raise TypeError unless args.all? {|a| a.is_a? Transformation }
@transformations = *args
end
def +(other)
case other
when Transformation
Composition.new(*transformations, ot... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/triangle.rb | Ruby | bsd-2-clause | 47 | main | 1,213 | require 'minitest/autorun'
require 'geometry/triangle'
describe Geometry::Triangle do
Triangle = Geometry::Triangle
it 'must always be closed' do
Triangle.new([0,0], [0,1], [1,0]).closed?.must_equal true
end
describe "when constructed with 3 points" do
let(:triangle) { Triangle.new [0,0], [0,1], [1... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/line.rb | Ruby | bsd-2-clause | 47 | main | 8,139 | require 'minitest/autorun'
require 'geometry/line'
describe Geometry::Line do
Line = Geometry::Line
Point = Geometry::Point
describe "when initializing" do
it "must accept two named points" do
line = Line.new(from:Point[0,0], to:Point[10,10])
line.must_be_kind_of(Line)
line.must_be_instanc... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/rotation.rb | Ruby | bsd-2-clause | 47 | main | 3,420 | require 'minitest/autorun'
require 'geometry/rotation'
describe Geometry::Rotation do
Point = Geometry::Point
Rotation = Geometry::Rotation
RotationAngle = Geometry::RotationAngle
describe "when constructed" do
it "must accept a rotation angle" do
rotation = Rotation.new angle:Math::PI/2
ro... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/point.rb | Ruby | bsd-2-clause | 47 | main | 10,712 | require 'minitest/autorun'
require 'geometry/point'
describe Geometry::Point do
PointIso = Geometry::PointIso
PointOne = Geometry::PointOne
PointZero = Geometry::PointZero
describe "class methods" do
it 'must generate a PointOne' do
Point.one.must_be_instance_of PointOne
end
it 'must generate... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/point_zero.rb | Ruby | bsd-2-clause | 47 | main | 6,224 | require 'minitest/autorun'
require 'geometry/point_zero'
describe Geometry::PointZero do
subject { Geometry::PointZero.new }
let(:zero) { Geometry::PointZero.new }
it 'must pop' do
subject.pop.must_equal Point[0]
subject.pop(2).must_equal Point[0, 0]
end
it 'must shift' do
subject.shift.must_e... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/vector.rb | Ruby | bsd-2-clause | 47 | main | 998 | require 'minitest/autorun'
require 'geometry/vector'
describe Vector do
describe "when monkeypatching Vector" do
let(:left) { Vector[1,2] }
let(:right) { Vector[3,4] }
it "must have +@" do
(+left).must_equal Vector[1,2]
end
it "must have unary negation" do
(-left).must_equal Vector[-1,-2]
end
... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/path.rb | Ruby | bsd-2-clause | 47 | main | 2,942 | require 'minitest/autorun'
require 'geometry/path'
describe Geometry::Path do
describe "construction" do
it "must create a Path with no arguments" do
path = Geometry::Path.new
path.must_be_kind_of Geometry::Path
path.elements.wont_be_nil
path.elements.size.must_equal 0
end
it "must create a... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/rectangle.rb | Ruby | bsd-2-clause | 47 | main | 5,014 | require 'minitest/autorun'
require 'geometry/rectangle'
def Rectangle(*args)
Geometry::Rectangle.new(*args)
end
describe Geometry::Rectangle do
Rectangle = Geometry::Rectangle
describe "when initializing" do
it "must accept two corners as Arrays" do
rectangle = Rectangle.new [1,2], [2,3]
recta... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/circle.rb | Ruby | bsd-2-clause | 47 | main | 3,871 | require 'minitest/autorun'
require 'geometry/circle'
describe Geometry::Circle do
Circle = Geometry::Circle
describe "when constructed with center and radius arguments" do
let(:circle) { Circle.new [1,2], 3 }
it "must create a Circle" do
circle.must_be_instance_of(Circle)
end
it "must have a cente... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/size_zero.rb | Ruby | bsd-2-clause | 47 | main | 3,711 | require 'minitest/autorun'
require 'geometry/size_zero'
describe Geometry::SizeZero do
Size = Geometry::Size
let(:zero) { Geometry::SizeZero.new }
describe "arithmetic" do
let(:left) { Size[1,2] }
let(:right) { Size[3,4] }
it "must have +@" do
(+zero).must_be :eql?, 0
(+zero).must_be_insta... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/polyline.rb | Ruby | bsd-2-clause | 47 | main | 12,034 | require 'minitest/autorun'
require 'geometry/polyline'
describe Geometry::Polyline do
Polyline = Geometry::Polyline
let(:closed_unit_square) { Polyline.new [0,0], [1,0], [1,1], [0,1], [0,0] }
let(:unit_square) { Polyline.new [0,0], [1,0], [1,1], [0,1] }
let(:reverse_unit_square) { Polyline.new [0,1], ... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/transformation.rb | Ruby | bsd-2-clause | 47 | main | 5,959 | require 'minitest/autorun'
require 'geometry/point'
require 'geometry/transformation'
describe Geometry::Transformation do
Transformation = Geometry::Transformation
describe "when constructed" do
it "must accept nothing and become an identity transformation" do
Transformation.new.identity?.must_equal tr... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/point_one.rb | Ruby | bsd-2-clause | 47 | main | 6,374 | require 'minitest/autorun'
require 'geometry/point_one'
describe Geometry::PointOne do
subject { Geometry::PointOne.new }
let(:one) { Geometry::PointOne.new }
it 'must pop' do
subject.pop.must_equal Point[1]
subject.pop(2).must_equal Point[1, 1]
end
it 'must shift' do
subject.shift.must_equal ... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/size.rb | Ruby | bsd-2-clause | 47 | main | 3,730 | require 'minitest/autorun'
require 'geometry/size'
describe Geometry::Size do
subject { Geometry::Size[10,10] }
describe "when constructed" do
it "create a Size object using list syntax" do
size = Geometry::Size[2,1]
assert_equal(2, size.size)
assert_equal(2, size.x)
assert_equal(1, size.... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/arc.rb | Ruby | bsd-2-clause | 47 | main | 3,994 | require 'minitest/autorun'
require 'geometry/arc'
describe Geometry::Arc do
Arc = Geometry::Arc
describe "when constructed" do
it "must accept a center point, radius, start and end angles" do
arc = Geometry::Arc.new center:[1,2], radius:3, start:0, end:90
arc.must_be_kind_of Geometry::Arc
arc.... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/bezier.rb | Ruby | bsd-2-clause | 47 | main | 650 | require 'minitest/autorun'
require 'geometry/bezier'
describe Geometry::Bezier do
subject { Geometry::Bezier.new [0,0], [1,1], [2,2], [3,3] }
it 'must have control points' do
subject.points.length.must_equal 4
end
it 'must generate Pascals Triangle' do
subject.binomial_coefficient(0).must_equal 1
... |
github | bfoz/geometry | https://github.com/bfoz/geometry | test/geometry/regular_polygon.rb | Ruby | bsd-2-clause | 47 | main | 4,766 | require 'minitest/autorun'
require 'geometry/regular_polygon'
describe Geometry::RegularPolygon do
RegularPolygon = Geometry::RegularPolygon
subject { RegularPolygon.new sides:4, center:[1,2], radius:3 }
it 'must always be closed' do
subject.closed?.must_equal true
end
describe 'when constructe... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.