Class: RSS::ITunesItemModel::ITunesDuration

Inherits:
Element
  • Object
show all
Includes:
RSS09
Defined in:
lib/rss/itunes.rb

Constant Summary

Constants included from RSS09

RSS09::ELEMENTS, RSS09::NSPOOL

Constants inherited from Element

Element::GET_ATTRIBUTES, Element::HAVE_CHILDREN_ELEMENTS, Element::INDENT, Element::MODELS, Element::MUST_CALL_VALIDATORS, Element::NEED_INITIALIZE_VARIABLES, Element::PLURAL_FORMS, Element::TO_ELEMENT_METHODS

Instance Attribute Summary collapse

Attributes inherited from Element

#do_validate, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RSS09

append_features

Methods inherited from Element

add_have_children_element, add_need_initialize_variable, add_plural_form, add_to_element_method, content_setup, #convert, #converter=, def_corresponded_attr_reader, def_corresponded_attr_writer, get_attributes, have_children_elements, have_content?, #have_xml_content?, inherited, inherited_base, install_get_attribute, install_model, install_must_call_validator, install_ns, models, must_call_validators, #need_base64_encode?, need_initialize_variables, need_parent?, plural_forms, #set_next_element, tag_name, #tag_name, to_element_methods, #to_s, #valid?, #validate, #validate_for_stream

Methods included from BaseModel

#install_date_element, #install_have_child_element, #install_have_children_element, #install_text_element

Methods included from Utils

element_initialize_arguments?, get_file_and_line_from_caller, new_with_value_if_need, to_class_name

Methods included from Utils::InheritedReader

#inherited_array_reader, #inherited_hash_reader, #inherited_reader

Methods included from SetupMaker

#setup_maker

Constructor Details

#initialize(*args) ⇒ ITunesDuration

Returns a new instance of ITunesDuration.



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/rss/itunes.rb', line 384

def initialize(*args)
  if Utils.element_initialize_arguments?(args)
    super
  else
    super()
    args = args[0] if args.size == 1 and args[0].is_a?(Array)
    if args.size == 1
      self.content = args[0]
    elsif args.size > 3
      raise ArgumentError,
              "must be (do_validate, params), (content), " +
              "(minute, second), ([minute, second]), "  +
              "(hour, minute, second) or ([hour, minute, second]): " +
              args.inspect
    else
      @second, @minute, @hour = args.reverse
      update_content
    end
  end
end

Instance Attribute Details

#hourObject

Returns the value of attribute hour.



383
384
385
# File 'lib/rss/itunes.rb', line 383

def hour
  @hour
end

#minuteObject

Returns the value of attribute minute.



383
384
385
# File 'lib/rss/itunes.rb', line 383

def minute
  @minute
end

#secondObject

Returns the value of attribute second.



383
384
385
# File 'lib/rss/itunes.rb', line 383

def second
  @second
end

Class Method Details

.construct(hours, minutes, seconds) ⇒ Object



358
359
360
361
362
363
364
365
366
367
368
# File 'lib/rss/itunes.rb', line 358

def construct(hours, minutes, seconds)
  components = [minutes, seconds]
  if components.include?(nil)
    nil
  else
    components.unshift(hours) if hours and hours > 0
    components.collect do |component|
      "%02d" % component
    end.join(':')
  end
end

.parse(duration, do_validate = true) ⇒ Object



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/rss/itunes.rb', line 334

def parse(duration, do_validate=true)
  if do_validate and /\A(?:
                          \d?\d:[0-5]\d:[0-5]\d|
                          [0-5]?\d:[0-5]\d|
                          \d+
                        )\z/x !~ duration
    raise ArgumentError,
            "must be one of HH:MM:SS, H:MM:SS, MM:SS, M:SS, S+: " +
            duration.inspect
  end

  if duration.include?(':')
    components = duration.split(':')
    components[3..-1] = nil if components.size > 3

    components.unshift("00") until components.size == 3
    components.collect do |component|
      component.to_i
    end
  else
    seconds_to_components(duration.to_i)
  end
end

.required_prefixObject



326
327
328
# File 'lib/rss/itunes.rb', line 326

def required_prefix
  ITUNES_PREFIX
end

.required_uriObject



330
331
332
# File 'lib/rss/itunes.rb', line 330

def required_uri
  ITUNES_URI
end

Instance Method Details

#content=(value) ⇒ Object Also known as: value=



405
406
407
408
409
410
411
412
413
414
415
416
417
418
# File 'lib/rss/itunes.rb', line 405

def content=(value)
  if value.nil?
    @content = nil
  elsif value.is_a?(self.class)
    self.content = value.content
  else
    begin
      @hour, @minute, @second = self.class.parse(value, @do_validate)
    rescue ArgumentError
      raise NotAvailableValueError.new(tag_name, value)
    end
    @content = value
  end
end

#full_nameObject



439
440
441
# File 'lib/rss/itunes.rb', line 439

def full_name
  tag_name_with_prefix(ITUNES_PREFIX)
end