Class: HQMF::Collection

Inherits:
Object
  • Object
show all
Includes:
HQMF::Conversion::Utilities
Defined in:
lib/hqmf-model/types.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HQMF::Conversion::Utilities

#build_hash, #check_equality, #json_array, #openstruct_to_json

Constructor Details

#initialize(type, values) ⇒ Collection

Returns a new instance of Collection.



432
433
434
435
# File 'lib/hqmf-model/types.rb', line 432

def initialize(type, values)
  @type = type || 'COL'
  @values = values || []
end

Instance Attribute Details

#typeObject

Returns the value of attribute type.



430
431
432
# File 'lib/hqmf-model/types.rb', line 430

def type
  @type
end

#valuesObject

Returns the value of attribute values.



430
431
432
# File 'lib/hqmf-model/types.rb', line 430

def values
  @values
end

Class Method Details

.from_json(json) ⇒ Object



437
438
439
440
441
442
443
# File 'lib/hqmf-model/types.rb', line 437

def self.from_json(json)
  json = json.with_indifferent_access
  values = []
  type = json['type']
  json['values'].each { |value| values.push(HQMF::DataCriteria.convert_value(value))}
  HQMF::Collection.new(type, values)
end

Instance Method Details

#==(other) ⇒ Object



452
453
454
# File 'lib/hqmf-model/types.rb', line 452

def ==(other)
  check_equality(self,other)
end

#to_jsonObject



445
446
447
448
449
450
# File 'lib/hqmf-model/types.rb', line 445

def to_json
  json = build_hash(self, [:type])
  json[:values] = []
  @values.each {|value| json[:values] << value.to_json  }
  json    
end