Class: ReaPack::Index::Provides

Inherits:
Struct
  • Object
show all
Defined in:
lib/reapack/index/provides.rb

Constant Summary collapse

PROVIDES_REGEX =
/
  \A
  (?: \[ \s* (?<options> .+? ) \s* \] )?
  \s*
  (?<pattern>.+?)
  (?:
    \s*>\s*(?<target>.+?)
  |
    \s+ (?<url_tpl>(?:file|https?):\/\/.+)
  )?
  \z
/x.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#file_patternObject

Returns the value of attribute file_pattern

Returns:

  • (Object)

    the current value of file_pattern



2
3
4
# File 'lib/reapack/index/provides.rb', line 2

def file_pattern
  @file_pattern
end

#mainObject Also known as: main?

Returns the value of attribute main

Returns:

  • (Object)

    the current value of main



2
3
4
# File 'lib/reapack/index/provides.rb', line 2

def main
  @main
end

#platformObject

Returns the value of attribute platform

Returns:

  • (Object)

    the current value of platform



2
3
4
# File 'lib/reapack/index/provides.rb', line 2

def platform
  @platform
end

#targetObject

Returns the value of attribute target

Returns:

  • (Object)

    the current value of target



2
3
4
# File 'lib/reapack/index/provides.rb', line 2

def target
  @target
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



2
3
4
# File 'lib/reapack/index/provides.rb', line 2

def type
  @type
end

#url_templateObject

Returns the value of attribute url_template

Returns:

  • (Object)

    the current value of url_template



2
3
4
# File 'lib/reapack/index/provides.rb', line 2

def url_template
  @url_template
end

Class Method Details

.parse(line) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/reapack/index/provides.rb', line 27

def parse(line)
  m = line.strip.match PROVIDES_REGEX
  return unless m

  instance = self.new m[:pattern], m[:url_tpl], m[:target]

  m[:options]&.split("\x20")&.each {|user_opt|
    user_opt.strip!
    next if user_opt.empty?

    opt = user_opt.downcase

    if Source.is_platform? opt
      instance.platform = opt.to_sym
    elsif type = ReaPack::Index.resolve_type(opt)
      instance.type = type
    elsif opt =~ /\A(nomain)|main(?:=(.+))?\Z/
      if $1 # nomain
        instance.main = false
      elsif $2 # explicit sections
        instance.main = $2.split(',').reject(&:empty?).map {|s| s.to_sym }
      else # implicit sections
        instance.main = true
      end
    else
      raise Error, "unknown option '#{user_opt}'"
    end
  }

  instance
end

.parse_each(input) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/reapack/index/provides.rb', line 19

def parse_each(input)
  if block_given?
    input.to_s.lines.map {|line| i = parse(line) and yield i }
  else
    enum_for :parse_each, input
  end
end