class ReaPack::Index::Source

Constants

FILE
MAIN
PLATFORM
PLATFORMS
SECTIONS
TAG
TYPE

Attributes

file[RW]
platform[R]
sections[R]
type[R]
url[RW]

Public Class Methods

is_platform?(input) click to toggle source
# File lib/reapack/index/source.rb, line 23
def is_platform?(input)
  PLATFORMS.has_key? input&.to_sym
end
new(url) click to toggle source
# File lib/reapack/index/source.rb, line 28
def initialize(url)
  @url = url
  @sections = []
  @platform = :all
end

Public Instance Methods

detect_sections(pkg) click to toggle source
# File lib/reapack/index/source.rb, line 57
def detect_sections(pkg)
  @sections = []

  if (@type || pkg.type) == :script
    @sections <<
      case pkg.topdir.downcase
      when 'midi editor'
        :midi_editor
      when 'midi inline editor'
        :midi_inlineeditor
      when 'midi event list editor'
        :midi_eventlisteditor
      when 'media explorer'
        :mediaexplorer
      else
        :main
      end
  end

  @sections.freeze # force going through sections=() for validation
end
make_node(parent) click to toggle source
# File lib/reapack/index/source.rb, line 89
def make_node(parent)
  @node = Nokogiri::XML::Node.new TAG, parent.document
  @node[MAIN] = @sections.join "\x20" unless @sections.empty?
  @node[PLATFORM] = @platform if @platform != :all
  @node[TYPE] = @type if @type
  @node[FILE] = @file if @file
  @node.content = Addressable::URI.parse(@url).normalize.to_s
  @node.parent = parent
rescue Addressable::URI::InvalidURIError => e
  raise Error, e.message
end
platform=(new_platform) click to toggle source
# File lib/reapack/index/source.rb, line 37
def platform=(new_platform)
  new_platform ||= :all

  unless self.class.is_platform? new_platform
    raise Error, "invalid platform '#{new_platform}'"
  end

  @platform = new_platform.to_sym
end
sections=(new_sections) click to toggle source
# File lib/reapack/index/source.rb, line 79
def sections=(new_sections)
  new_sections.each {|s|
    unless SECTIONS.include? s
      raise Error, "invalid Action List section '#{s}'"
    end
  }

  @sections = new_sections.sort {|s| SECTIONS.index s }.freeze
end
type=(new_type) click to toggle source
# File lib/reapack/index/source.rb, line 47
def type=(new_type)
  return @type = new_type if new_type.nil?

  unless ReaPack::Index.is_type? new_type
    raise Error, "invalid type '#{new_type}'"
  end

  @type = new_type.to_sym
end