module BoilerPlater
Public Class Methods
config(c=nil)
click to toggle source
# File lib/parser.rb, line 3 def self.config(c=nil) @config = c if !c.nil? @config || OpenStruct.new end
get(gist_id)
click to toggle source
# File lib/parser.rb, line 13 def self.get(gist_id) Gist.read(gist_id) end
list()
click to toggle source
# 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)
click to toggle source
# File lib/parser.rb, line 32 def self.search(name) list.find { |k, v| v =~ /#{name}/ }.join(' | ') end
sections(content)
click to toggle source
# 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)| ... }
click to toggle source
# File lib/parser.rb, line 8 def self.setup(&block) c = config yield c && config(c) end
show(gist_id)
click to toggle source
# File lib/parser.rb, line 17 def self.show(gist_id) JSON.parse(open(Gist::GIST_URL % gist_id).read) end
use(gist_id)
click to toggle source
# 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