Class: Giri::TextNodeDuration
- Inherits:
-
TextNodeString
- Object
- String
- TextNodeString
- Giri::TextNodeDuration
- Defined in:
- lib/giri/text_node_duration.rb
Overview
Instance Method Summary collapse
Methods inherited from TextNodeString
Methods included from Bud
#big_decimal_node, #build_attribute_name, #build_type, #date_time_node, #duration_node, extended, #inherited, #integer_node, #spawn, #text_node, #xml_attribute, #xml_node, #xml_node_collection
Constructor Details
This class inherits a constructor from Giri::TextNodeString
Instance Method Details
#components ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/giri/text_node_duration.rb', line 4 def components @components ||= begin _, years, months, days, time_part, hours, minutes, seconds = self.match(/\AP(\d+Y)?(\d+M)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?\z/).to_a # Example of values "15H" and "15H".to_i will get 15. { years: years.to_i, months: months.to_i, days: days.to_i, hours: hours.to_i, minutes: minutes.to_i, seconds: seconds.to_i, } end end |
#duration_time ⇒ Object
19 20 21 22 23 |
# File 'lib/giri/text_node_duration.rb', line 19 def duration_time components.reduce(0) do |acc,(k,v)| acc + v.public_send(k) end end |