Class: Namo
- Inherits:
-
Object
- Object
- Namo
- Includes:
- Enumerable
- Defined in:
- lib/namo.rb,
lib/Namo/VERSION.rb
Overview
Namo/VERSION.rb Namo::VERSION
Defined Under Namespace
Classes: Row
Constant Summary collapse
- VERSION =
'0.2.0'
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#formulae ⇒ Object
Returns the value of attribute formulae.
Instance Method Summary collapse
- #[](*names, **selections) ⇒ Object
- #[]=(name, proc) ⇒ Object
- #coordinates ⇒ Object
- #dimensions ⇒ Object
- #each(&block) ⇒ Object
- #to_a ⇒ Object
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
39 40 41 |
# File 'lib/namo.rb', line 39 def data @data end |
#formulae ⇒ Object
Returns the value of attribute formulae.
40 41 42 |
# File 'lib/namo.rb', line 40 def formulae @formulae end |
Instance Method Details
#[](*names, **selections) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/namo.rb', line 54 def [](*names, **selections) rows = selections.any? ? select{|row| row.match?(selections)} : entries data = ( if names.any? rows.map do |row| names.each_with_object({}){|name, hash| hash[name] = row[name]} end else rows.map(&:to_h) end ) self.class.new(data, formulae: @formulae.dup) end |
#[]=(name, proc) ⇒ Object
68 69 70 |
# File 'lib/namo.rb', line 68 def []=(name, proc) @formulae[name] = proc end |
#coordinates ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/namo.rb', line 46 def coordinates @coordinates ||= ( dimensions.each_with_object({}) do |dimension, hash| hash[dimension] = @data.map{|row| row[dimension]}.uniq end ) end |
#dimensions ⇒ Object
42 43 44 |
# File 'lib/namo.rb', line 42 def dimensions @dimensions ||= @data.first.keys end |
#each(&block) ⇒ Object
72 73 74 75 |
# File 'lib/namo.rb', line 72 def each(&block) return enum_for(:each) unless block_given? @data.each{|row_data| block.call(Row.new(row_data, @formulae))} end |
#to_a ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/namo.rb', line 77 def to_a @data.map do |row| row.keys.each_with_object({}) do |key, hash| hash[key] = row[key] end end end |