Class: AwesomeXML::Duration::Format::DynamicChunk

Inherits:
Object
  • Object
show all
Defined in:
lib/awesome_xml/duration/format/dynamic_chunk.rb

Defined Under Namespace

Classes: InvalidDurationUnit, InvalidParseLength

Constant Summary collapse

UNITS =
{ 'D' => :days, 'H' => :hours, 'M' => :minutes, 'S' => :seconds}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDynamicChunk

Returns a new instance of DynamicChunk.



14
15
16
# File 'lib/awesome_xml/duration/format/dynamic_chunk.rb', line 14

def initialize
  @format_chars = []
end

Instance Attribute Details

#delimiterObject

Returns the value of attribute delimiter.



12
13
14
# File 'lib/awesome_xml/duration/format/dynamic_chunk.rb', line 12

def delimiter
  @delimiter
end

#format_charsObject

Returns the value of attribute format_chars.



12
13
14
# File 'lib/awesome_xml/duration/format/dynamic_chunk.rb', line 12

def format_chars
  @format_chars
end

Instance Method Details

#dynamic?Boolean

Counterpart of the same method of ‘AwesomeXML::Duration::Format::DynamicChunk`. Used to differentiate between instances of these two classes.

Returns:

  • (Boolean)


25
26
27
# File 'lib/awesome_xml/duration/format/dynamic_chunk.rb', line 25

def dynamic?
  true
end

#parse_lengthObject

Takes the characters following the first character of ‘format_chars` and interprets them as an integer representing the number of characters to parse when given to the `AweseomXML::Duration::ChunkParser` together with a piece of duration string. When the `format_chars` only contain a single character, this will be 0.



39
40
41
42
# File 'lib/awesome_xml/duration/format/dynamic_chunk.rb', line 39

def parse_length
  fail InvalidParseLength.new(parsed_parse_length) unless valid_parse_length?
  @parse_length ||= parsed_parse_length.to_i
end

#to_sObject

Returns the defining characters joint into a string.



19
20
21
# File 'lib/awesome_xml/duration/format/dynamic_chunk.rb', line 19

def to_s
  [format_chars, delimiter].join
end

#unitObject

Takes the first character of ‘format_chars` and interprets as a duration unit.



30
31
32
33
# File 'lib/awesome_xml/duration/format/dynamic_chunk.rb', line 30

def unit
  fail InvalidDurationUnit.new(parsed_unit) unless valid_unit?
  @unit ||= UNITS[parsed_unit]
end