Module: BoilerPlater
- Defined in:
- lib/cmd.rb,
lib/parser.rb
Defined Under Namespace
Class Method Summary collapse
- .config(c = nil) ⇒ Object
- .get(gist_id) ⇒ Object
- .list ⇒ Object
- .search(name) ⇒ Object
- .sections(content) ⇒ Object
- .setup {|c && config(c)| ... } ⇒ Object
- .show(gist_id) ⇒ Object
- .use(gist_id) ⇒ Object
Class Method Details
.config(c = nil) ⇒ Object
3 4 5 6 |
# File 'lib/parser.rb', line 3 def self.config(c=nil) @config = c if !c.nil? @config || OpenStruct.new end |
.get(gist_id) ⇒ Object
13 14 15 |
# File 'lib/parser.rb', line 13 def self.get(gist_id) Gist.read(gist_id) end |
.list ⇒ Object
28 29 30 |
# File 'lib/parser.rb', line 28 def self.list get(3266785).each_line.map { |l| l.split(';') }.inject({}) { |r, l| r[l.first.to_i] = l.last.strip; r } end |
.search(name) ⇒ Object
32 33 34 |
# File 'lib/parser.rb', line 32 def self.search(name) list.find { |k, v| v =~ /#{name}/ }.join(' | ') end |
.sections(content) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/parser.rb', line 36 def self.sections(content) sections, section = [], '' content.each_line do |line| if line =~ /^##/ sections << Parser::Section.new(section) if !section.empty? section = line else section += line end end sections << Parser::Section.new(section) end |
.setup {|c && config(c)| ... } ⇒ Object
8 9 10 11 |
# File 'lib/parser.rb', line 8 def self.setup(&block) c = config yield c && config(c) end |
.show(gist_id) ⇒ Object
17 18 19 |
# File 'lib/parser.rb', line 17 def self.show(gist_id) JSON.parse(open(Gist::GIST_URL % gist_id).read) end |
.use(gist_id) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/parser.rb', line 21 def self.use(gist_id) BoilerPlater.sections(get(gist_id)).each do |f| f.download_content! unless f.content? f.save! end end |