class AwesomeXML::Duration::Format::DynamicChunk

Constants

UNITS

Attributes

delimiter[RW]
format_chars[RW]

Public Class Methods

new() click to toggle source
# File lib/awesome_xml/duration/format/dynamic_chunk.rb, line 14
def initialize
  @format_chars = []
end

Public Instance Methods

dynamic?() click to toggle source

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

# File lib/awesome_xml/duration/format/dynamic_chunk.rb, line 25
def dynamic?
  true
end
parse_length() click to toggle source

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.

# 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() click to toggle source

Returns the defining characters joint into a string.

# File lib/awesome_xml/duration/format/dynamic_chunk.rb, line 19
def to_s
  [format_chars, delimiter].join
end
unit() click to toggle source

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

# 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

Private Instance Methods

parsed_parse_length() click to toggle source
# File lib/awesome_xml/duration/format/dynamic_chunk.rb, line 58
def parsed_parse_length
  @parsed_parse_length ||= format_chars.drop(1).join
end
parsed_unit() click to toggle source
# File lib/awesome_xml/duration/format/dynamic_chunk.rb, line 50
def parsed_unit
  format_chars[0].upcase
end
valid_parse_length?() click to toggle source
# File lib/awesome_xml/duration/format/dynamic_chunk.rb, line 54
def valid_parse_length?
  parsed_parse_length =~ /^[0-9]*$/ || parsed_parse_length.nil?
end
valid_unit?() click to toggle source
# File lib/awesome_xml/duration/format/dynamic_chunk.rb, line 46
def valid_unit?
  %w(D H M S).include?(parsed_unit)
end