Class: IceCube::IcalBuilder
- Inherits:
-
Object
- Object
- IceCube::IcalBuilder
- Defined in:
- lib/ice_cube/builders/ical_builder.rb
Constant Summary collapse
- ICAL_DAYS =
["SU", "MO", "TU", "WE", "TH", "FR", "SA"]
Class Method Summary collapse
- .fixnum_to_ical_day(num) ⇒ Object
- .ical_duration(duration) ⇒ Object
- .ical_format(time, force_utc) ⇒ Object
- .ical_utc_format(time) ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize ⇒ IcalBuilder
constructor
A new instance of IcalBuilder.
-
#to_s ⇒ Object
Build for a single rule entry.
Constructor Details
#initialize ⇒ IcalBuilder
Returns a new instance of IcalBuilder.
5 6 7 |
# File 'lib/ice_cube/builders/ical_builder.rb', line 5 def initialize @hash = {} end |
Class Method Details
.fixnum_to_ical_day(num) ⇒ Object
9 10 11 |
# File 'lib/ice_cube/builders/ical_builder.rb', line 9 def self.fixnum_to_ical_day(num) ICAL_DAYS[num] end |
.ical_duration(duration) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ice_cube/builders/ical_builder.rb', line 45 def self.ical_duration(duration) hours = duration / 3600 duration %= 3600 minutes = duration / 60 duration %= 60 repr = "" repr << "#{hours}H" if hours > 0 repr << "#{minutes}M" if minutes > 0 repr << "#{duration}S" if duration > 0 "PT#{repr}" end |
.ical_format(time, force_utc) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/ice_cube/builders/ical_builder.rb', line 36 def self.ical_format(time, force_utc) time = time.dup.utc if force_utc if time.utc? ":#{IceCube::I18n.l(time, format: "%Y%m%dT%H%M%SZ")}" # utc time else ";TZID=#{IceCube::I18n.l(time, format: "%Z:%Y%m%dT%H%M%S")}" # local time specified end end |
Instance Method Details
#[](key) ⇒ Object
13 14 15 |
# File 'lib/ice_cube/builders/ical_builder.rb', line 13 def [](key) @hash[key] ||= [] end |
#to_s ⇒ Object
Build for a single rule entry
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ice_cube/builders/ical_builder.rb', line 18 def to_s arr = [] if (freq = @hash.delete("FREQ")) arr << "FREQ=#{freq.join(",")}" end arr.concat(@hash.map do |key, value| if value.is_a?(Array) "#{key}=#{value.join(",")}" end end.compact) arr.join(";") end |