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.
6 7 8 |
# File 'lib/divISOr/iso_records.rb', line 6 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.
4 5 6 |
# File 'lib/divISOr/iso_records.rb', line 4 def data @data end |
Instance Method Details
#all(value, fields) ⇒ Object
15 16 17 18 19 |
# File 'lib/divISOr/iso_records.rb', line 15 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
10 11 12 13 |
# File 'lib/divISOr/iso_records.rb', line 10 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 |