Class: Applyrics::Lyricsfile

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Lyricsfile

Returns a new instance of Lyricsfile.



35
36
37
38
# File 'lib/applyrics/lyricsfile.rb', line 35

def initialize(path=nil)
  @path = File.expand_path(path)
  parse(File.read(@path))
end

Class Method Details

.exist?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/applyrics/lyricsfile.rb', line 4

def exist?
  File.exist?("./Lyricsfile")
end

.generate(config = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/applyrics/lyricsfile.rb', line 7

def generate(config=nil)
  template = File.read("#{Gem::Specification.find_by_name('applyrics').gem_dir}/lib/assets/LyricsfileTemplate")

  if config.key?(:account_id)
    template.gsub!('[[ACCOUNT_ID]]', config[:account_id])
  else
    template.gsub!('[[ACCOUNT_ID]]', 'your-account-id')
    template.gsub!('account:', '# account:')
  end

  if config.key?(:project_key)
    template.gsub!('[[PROJECT_KEY]]', config[:project_key])
  else
    template.gsub!('[[PROJECT_KEY]]', 'your-project-key')
    template.gsub!('project:', '# project:')
  end

  if config.key?(:filename)
    template.gsub!('[[FILENAME]]', config[:filename])
  else
    template.gsub!('[[FILENAME]]', 'lyrics.json')
    template.gsub!('filename:', '# filename:')
  end

  File.write("./Lyricsfile", template)
end

Instance Method Details

#parse(data) ⇒ Object



42
43
44
45
46
47
# File 'lib/applyrics/lyricsfile.rb', line 42

def parse(data)
  begin
     eval(data, parse_binding)
   rescue SyntaxError => ex
   end
end

#parse_bindingObject



39
40
41
# File 'lib/applyrics/lyricsfile.rb', line 39

def parse_binding
  binding
end