Class: XcodeArchiveCache::BuildSettings::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/build_settings/parser.rb

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



5
6
7
8
9
10
# File 'lib/build_settings/parser.rb', line 5

def initialize
  @setting_name_regex = Regexp.new("^(?<#{SETTING_NAME_GROUP}>#{SETTING_NAME_CHARACTERS})\s=")
  @setting_value_regex = Regexp.new("^#{SETTING_NAME_CHARACTERS}\s=\s(?<#{SETTING_VALUE_GROUP}>.+)$")
  @setting_entry_regex = create_entry_regex
  @setting_entry_name_regex = Regexp.new(SETTING_NAME_CHARACTERS)
end

Instance Method Details

#create_entry_regex(characters = SETTING_NAME_CHARACTERS) ⇒ Regexp

Parameters:

  • characters (String) (defaults to: SETTING_NAME_CHARACTERS)

Returns:

  • (Regexp)


50
51
52
# File 'lib/build_settings/parser.rb', line 50

def create_entry_regex(characters = SETTING_NAME_CHARACTERS)
  Regexp.new("\\$[({]#{characters}[)}]")
end

#find_all_names(string) ⇒ Array<String>

Parameters:

  • string (String)

Returns:

  • (Array<String>)


16
17
18
19
20
21
22
# File 'lib/build_settings/parser.rb', line 16

def find_all_names(string)
  string.scan(setting_entry_regex)
      .map {|entry| entry.scan(setting_entry_name_regex).first}
      .flatten
      .compact
      .uniq
end

#parse_name(string) ⇒ String

Parameters:

  • string (String)

Returns:

  • (String)


28
29
30
31
32
33
# File 'lib/build_settings/parser.rb', line 28

def parse_name(string)
  match = setting_name_regex.match(string)
  return nil unless match

  match[SETTING_NAME_GROUP]
end

#parse_value(string) ⇒ String

Parameters:

  • string (String)

Returns:

  • (String)


39
40
41
42
43
44
# File 'lib/build_settings/parser.rb', line 39

def parse_value(string)
  match = setting_value_regex.match(string)
  return nil unless match

  match[SETTING_VALUE_GROUP]
end