Class | RSS::ITunesItemModel::ITunesDuration |
In: |
lib/rss/itunes.rb
|
Parent: | Element |
content | -> | value |
hour | [R] | |
minute | [R] | |
second | [R] |
# File lib/rss/itunes.rb, line 294 294: def construct(hour, minute, second) 295: components = [minute, second] 296: if components.include?(nil) 297: nil 298: else 299: components.unshift(hour) if hour and hour > 0 300: components.collect do |component| 301: "%02d" % component 302: end.join(":") 303: end 304: end
# File lib/rss/itunes.rb, line 312 312: def initialize(*args) 313: if Utils.element_initialize_arguments?(args) 314: super 315: else 316: super() 317: args = args[0] if args.size == 1 and args[0].is_a?(Array) 318: if args.size == 1 319: self.content = args[0] 320: elsif args.size > 3 321: raise ArgumentError, 322: "must be (do_validate, params), (content), " + 323: "(minute, second), ([minute, second]), " + 324: "(hour, minute, second) or ([hour, minute, second]): " + 325: args.inspect 326: else 327: @second, @minute, @hour = args.reverse 328: update_content 329: end 330: end 331: end
# File lib/rss/itunes.rb, line 274 274: def parse(duration, do_validate=true) 275: if do_validate and /\A(?: 276: \d?\d:[0-5]\d:[0-5]\d| 277: [0-5]?\d:[0-5]\d 278: )\z/x !~ duration 279: raise ArgumentError, 280: "must be one of HH:MM:SS, H:MM:SS, MM::SS, M:SS: " + 281: duration.inspect 282: end 283: 284: components = duration.split(':') 285: components[3..-1] = nil if components.size > 3 286: 287: components.unshift("00") until components.size == 3 288: 289: components.collect do |component| 290: component.to_i 291: end 292: end
# File lib/rss/itunes.rb, line 333 333: def content=(value) 334: if value.nil? 335: @content = nil 336: elsif value.is_a?(self.class) 337: self.content = value.content 338: else 339: begin 340: @hour, @minute, @second = self.class.parse(value, @do_validate) 341: rescue ArgumentError 342: raise NotAvailableValueError.new(tag_name, value) 343: end 344: @content = value 345: end 346: end
# File lib/rss/itunes.rb, line 367 367: def full_name 368: tag_name_with_prefix(ITUNES_PREFIX) 369: end
# File lib/rss/itunes.rb, line 349 349: def hour=(hour) 350: @hour = @do_validate ? Integer(hour) : hour.to_i 351: update_content 352: hour 353: end
# File lib/rss/itunes.rb, line 355 355: def minute=(minute) 356: @minute = @do_validate ? Integer(minute) : minute.to_i 357: update_content 358: minute 359: end
# File lib/rss/itunes.rb, line 361 361: def second=(second) 362: @second = @do_validate ? Integer(second) : second.to_i 363: update_content 364: second 365: end
# File lib/rss/itunes.rb, line 376 376: def maker_target(target) 377: if @content 378: target.itunes_duration {|duration| duration} 379: else 380: nil 381: end 382: end
# File lib/rss/itunes.rb, line 384 384: def setup_maker_element(duration) 385: super(duration) 386: duration.content = @content 387: end