Class: AQI::CPT

Inherits:
Object
  • Object
show all
Defined in:
lib/aqi/cpt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CPT

Returns a new instance of CPT.



5
6
7
8
9
# File 'lib/aqi/cpt.rb', line 5

def initialize(options)
  self.rank     = options[:rank]
  self.value    = validate_value(options[:value])
  self.modifier = options[:modifier]
end

Instance Attribute Details

#modifierObject

Returns the value of attribute modifier.



3
4
5
# File 'lib/aqi/cpt.rb', line 3

def modifier
  @modifier
end

#rankObject

Returns the value of attribute rank.



3
4
5
# File 'lib/aqi/cpt.rb', line 3

def rank
  @rank
end

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/aqi/cpt.rb', line 3

def value
  @value
end

Instance Method Details

#to_xmlObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/aqi/cpt.rb', line 15

def to_xml
  return '' unless value

  builder = Builder::XmlMarkup.new
  builder.CPT do |cpt|
    cpt.CPTRank(rank)          if rank
    cpt.CPTValue(value)
    cpt.CPTModifier(modifier)  if modifier
  end
end

#validate_value(value) ⇒ Object



11
12
13
# File 'lib/aqi/cpt.rb', line 11

def validate_value(value)
  value =~ /\d\d\d\d[\w\d]/ ? value : nil
end