Class: KDL::Types::Duration

Inherits:
Value
  • Object
show all
Defined in:
lib/kdl/types/duration.rb,
lib/kdl/types/duration/iso8601_parser.rb

Defined Under Namespace

Classes: ISO8601Parser

Constant Summary

Constants inherited from Value

Value::Null

Instance Attribute Summary collapse

Attributes inherited from Value

#format, #type, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Value

#as_type, from, #stringify_value, #to_s

Constructor Details

#initialize(parts = {}, format: nil, type: 'duration') ⇒ Duration

Returns a new instance of Duration.



8
9
10
11
12
13
14
15
16
17
# File 'lib/kdl/types/duration.rb', line 8

def initialize(parts = {}, format: nil, type: 'duration')
  super
  @years = parts.fetch(:years, 0)
  @months = parts.fetch(:months, 0)
  @weeks = parts.fetch(:weeks, 0)
  @days = parts.fetch(:days, 0)
  @hours = parts.fetch(:hours, 0)
  @minutes = parts.fetch(:minutes, 0)
  @seconds = parts.fetch(:seconds, 0)
end

Instance Attribute Details

#daysObject (readonly)

Returns the value of attribute days.



6
7
8
# File 'lib/kdl/types/duration.rb', line 6

def days
  @days
end

#hoursObject (readonly)

Returns the value of attribute hours.



6
7
8
# File 'lib/kdl/types/duration.rb', line 6

def hours
  @hours
end

#minutesObject (readonly)

Returns the value of attribute minutes.



6
7
8
# File 'lib/kdl/types/duration.rb', line 6

def minutes
  @minutes
end

#monthsObject (readonly)

Returns the value of attribute months.



6
7
8
# File 'lib/kdl/types/duration.rb', line 6

def months
  @months
end

#secondsObject (readonly)

Returns the value of attribute seconds.



6
7
8
# File 'lib/kdl/types/duration.rb', line 6

def seconds
  @seconds
end

#weeksObject (readonly)

Returns the value of attribute weeks.



6
7
8
# File 'lib/kdl/types/duration.rb', line 6

def weeks
  @weeks
end

#yearsObject (readonly)

Returns the value of attribute years.



6
7
8
# File 'lib/kdl/types/duration.rb', line 6

def years
  @years
end

Class Method Details

.call(value, type = 'duration') ⇒ Object



19
20
21
22
23
24
# File 'lib/kdl/types/duration.rb', line 19

def self.call(value, type = 'duration')
  return nil unless value.is_a? ::KDL::Value::String

  parts = ISO8601Parser.new(value.value).parse!
  new(parts, type: type)
end