Class: Applyrics::StringsFile::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/applyrics/stringsfile.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Parser

Returns a new instance of Parser.



61
62
63
64
65
66
67
# File 'lib/applyrics/stringsfile.rb', line 61

def initialize(hash)
  @hash = hash
  @property_regex = %r/\A(.*?)=(.*)\z/u
  @quote          = %r/"([^"]+)"/u
  @open_quote     = %r/\A\s*(".*)\z/u
  @comment_regex  = %r/\/\*([^*]+)\*\//u
end

Instance Method Details

#parse(data) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/applyrics/stringsfile.rb', line 69

def parse(data)
  @hash.clear
  data.each_line do |line|
    @line = line.chomp

    case @line
    when @comment_regex
      # Not implemented
    when @property_regex
      key = strip($1)
      value = strip($2)
      @hash[key] = value
    end
  end

  @hash
end

#strip(value) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/applyrics/stringsfile.rb', line 87

def strip(value)
  str = @quote.match(value.strip)
  if str.nil?
    value.strip
  else
    str[1]
  end
end