Class: Cldr::Format::Datetime

Inherits:
Object
  • Object
show all
Defined in:
lib/cldr/format/datetime.rb,
lib/cldr/format/datetime/base.rb

Defined Under Namespace

Classes: Base

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format, date, time) ⇒ Datetime

Returns a new instance of Datetime.



8
9
10
# File 'lib/cldr/format/datetime.rb', line 8

def initialize(format, date, time)
  @format, @date, @time = format, date, time
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



6
7
8
# File 'lib/cldr/format/datetime.rb', line 6

def date
  @date
end

#formatObject (readonly)

Returns the value of attribute format.



6
7
8
# File 'lib/cldr/format/datetime.rb', line 6

def format
  @format
end

#timeObject (readonly)

Returns the value of attribute time.



6
7
8
# File 'lib/cldr/format/datetime.rb', line 6

def time
  @time
end

Instance Method Details

#apply(datetime, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/cldr/format/datetime.rb', line 12

def apply(datetime, options = {})
  format.gsub(/(\{\{(date|time)\}\})/) do
    case $2
    when 'date'
      options[:date] || date.apply(datetime, options)
    when 'time'
      options[:time] || time.apply(datetime, options)
    end
  end
end