Class: HQMF::Ratio

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Conversion::Utilities

#build_hash, #check_equality, #json_array, #openstruct_to_json

Constructor Details

#initialize(type, numerator, denominator) ⇒ Ratio

Returns a new instance of Ratio.

Parameters:

  • type (String)
  • numerator (Value)
  • denominator (Value)


464
465
466
467
468
# File 'lib/hqmf-model/types.rb', line 464

def initialize(type, numerator, denominator)
  @type = type || 'RT'
  @numerator = numerator
  @denominator = denominator
end

Instance Attribute Details

#denominatorObject

Returns the value of attribute denominator.



459
460
461
# File 'lib/hqmf-model/types.rb', line 459

def denominator
  @denominator
end

#numeratorObject

Returns the value of attribute numerator.



459
460
461
# File 'lib/hqmf-model/types.rb', line 459

def numerator
  @numerator
end

#typeObject

Returns the value of attribute type.



459
460
461
# File 'lib/hqmf-model/types.rb', line 459

def type
  @type
end

Class Method Details

.from_json(json) ⇒ Object



470
471
472
473
474
475
# File 'lib/hqmf-model/types.rb', line 470

def self.from_json(json)
  type = json["type"] if json["type"]
  numerator = json["numerator"] if json["numerator"]
  denominator = json["denominator"] if json["denominator"]
  HQMF::Ratio.new(type, numerator, denominator)
end

Instance Method Details

#==(other) ⇒ Object



489
490
491
# File 'lib/hqmf-model/types.rb', line 489

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

#denominator?Boolean

Returns:

  • (Boolean)


481
482
483
# File 'lib/hqmf-model/types.rb', line 481

def denominator?
  @denominator
end

#numerator?Boolean

Returns:

  • (Boolean)


477
478
479
# File 'lib/hqmf-model/types.rb', line 477

def numerator?
  @numerator
end

#to_jsonObject



485
486
487
# File 'lib/hqmf-model/types.rb', line 485

def to_json
  build_hash(self, [:type, :numerator, :denominator])
end