Class: Applyrics::Lyricsfile
- Inherits:
-
Object
- Object
- Applyrics::Lyricsfile
- Defined in:
- lib/applyrics/lyricsfile.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path = nil) ⇒ Lyricsfile
constructor
A new instance of Lyricsfile.
- #parse(data) ⇒ Object
- #parse_binding ⇒ Object
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.(path) parse(File.read(@path)) end |
Class Method Details
.exist? ⇒ 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_binding ⇒ Object
39 40 41 |
# File 'lib/applyrics/lyricsfile.rb', line 39 def parse_binding binding end |