Class: AwesomeXML::Duration::Format::DynamicChunk
- Inherits:
-
Object
- Object
- AwesomeXML::Duration::Format::DynamicChunk
- 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
-
#delimiter ⇒ Object
Returns the value of attribute delimiter.
-
#format_chars ⇒ Object
Returns the value of attribute format_chars.
Instance Method Summary collapse
-
#dynamic? ⇒ Boolean
Counterpart of the same method of ‘AwesomeXML::Duration::Format::DynamicChunk`.
-
#initialize ⇒ DynamicChunk
constructor
A new instance of DynamicChunk.
-
#parse_length ⇒ Object
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.
-
#to_s ⇒ Object
Returns the defining characters joint into a string.
-
#unit ⇒ Object
Takes the first character of ‘format_chars` and interprets as a duration unit.
Constructor Details
#initialize ⇒ DynamicChunk
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
#delimiter ⇒ Object
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_chars ⇒ Object
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.
25 26 27 |
# File 'lib/awesome_xml/duration/format/dynamic_chunk.rb', line 25 def dynamic? true end |
#parse_length ⇒ Object
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_s ⇒ Object
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 |
#unit ⇒ Object
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 |