Class: BoilerPlater::Parser::Section

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentObject (readonly)

Returns the value of attribute content.



67
68
69
# File 'lib/parser.rb', line 67

def content
  @content
end

#fileObject (readonly)

Returns the value of attribute file.



65
66
67
# File 'lib/parser.rb', line 65

def file
  @file
end

#metadataObject (readonly)

Returns the value of attribute metadata.



66
67
68
# File 'lib/parser.rb', line 66

def 
  @metadata
end

Instance Method Details

#content?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


88
89
90
# File 'lib/parser.rb', line 88

def exists?
  File.exists? path
end

#pathObject



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