Class: BoilerPlater::Parser::Section
- Inherits:
-
Object
- Object
- BoilerPlater::Parser::Section
- Defined in:
- lib/parser.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
- #content? ⇒ Boolean
- #download_content! ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(content) ⇒ Section
constructor
A new instance of Section.
- #path ⇒ Object
- #save! ⇒ Object
Constructor Details
#initialize(content) ⇒ Section
Returns a new instance of Section.
69 70 71 72 73 74 |
# File 'lib/parser.rb', line 69 def initialize(content) @content = content.split("\n") @metadata = (@content.shift.strip) @content = @content.join("\n") @file = @metadata[:filename] end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
67 68 69 |
# File 'lib/parser.rb', line 67 def content @content end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
65 66 67 |
# File 'lib/parser.rb', line 65 def file @file end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
66 67 68 |
# File 'lib/parser.rb', line 66 def @metadata end |
Instance Method Details
#content? ⇒ Boolean
96 97 98 |
# File 'lib/parser.rb', line 96 def content? !content.empty? end |
#download_content! ⇒ Object
92 93 94 |
# File 'lib/parser.rb', line 92 def download_content! @content = open([:url]).read end |
#exists? ⇒ Boolean
88 89 90 |
# File 'lib/parser.rb', line 88 def exists? File.exists? path end |
#path ⇒ Object
83 84 85 86 |
# File 'lib/parser.rb', line 83 def path FileUtils.mkdir_p(BoilerPlater.config.prefix) if !BoilerPlater.config.prefix.nil? File.join(BoilerPlater.config.prefix || '.', File.dirname(@file), File.basename(@file)) end |
#save! ⇒ Object
76 77 78 79 80 81 |
# File 'lib/parser.rb', line 76 def save! FileUtils.mkdir_p(File.dirname(path)) unless File.directory?(File.dirname(path)) File.open(path, 'w') do |f| f.puts(content) end end |