Class: ISORecords
- Inherits:
-
Object
- Object
- ISORecords
- Defined in:
- lib/divISOr/iso_records.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #all(value, fields) ⇒ Object
-
#initialize(path) ⇒ ISORecords
constructor
A new instance of ISORecords.
- #values_for(fields) ⇒ Object
Constructor Details
#initialize(path) ⇒ ISORecords
Returns a new instance of ISORecords.
5 6 7 |
# File 'lib/divISOr/iso_records.rb', line 5 def initialize(path) @data = JSON.parse(File.read(path), :symbolize_names => true) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/divISOr/iso_records.rb', line 3 def data @data end |
Instance Method Details
#all(value, fields) ⇒ Object
14 15 16 17 18 |
# File 'lib/divISOr/iso_records.rb', line 14 def all(value, fields) fields = [fields] unless fields.is_a?(Array) return data if value.nil? data.select{|record| fields.any?{|field| record[field] == value}} end |
#values_for(fields) ⇒ Object
9 10 11 12 |
# File 'lib/divISOr/iso_records.rb', line 9 def values_for(fields) fields = [fields] unless fields.is_a?(Array) data.map{|record| fields.map{|field| record[field.to_sym] }}.flatten.compact.map(&:upcase) end |