Class: TextUtils::Page
- Inherits:
-
Object
- Object
- TextUtils::Page
- Defined in:
- lib/textutils/page.rb
Overview
fix:
add some unit tests!!!!!!!!!!!!!!!!!
Class Method Summary collapse
- .create(path, opts = {}) {|page| ... } ⇒ Object
-
.open(path, mode, opts = {}) {|page| ... } ⇒ Object
convenience helper; use like: Page.open() do |page| page.write( text ) page.write( text ) end.
- .update(path, opts = {}) {|page| ... } ⇒ Object
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(path, mode, opts = {}) ⇒ Page
constructor
A new instance of Page.
- #write(text) ⇒ Object
Constructor Details
#initialize(path, mode, opts = {}) ⇒ Page
Returns a new instance of Page.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/textutils/page.rb', line 46 def initialize( path, mode, opts={} ) ## check if folders exists? if not create folder in path FileUtils.mkdir_p( File.dirname(path) ) @file = File.new( path, mode ) ## add frontmatter if passed in ## todo: assert check if mode = 'w' and NOT 'a' !!! @file.write render_frontmatter( opts[:frontmatter] ) if opts[:frontmatter] end |
Class Method Details
.create(path, opts = {}) {|page| ... } ⇒ Object
31 32 33 34 35 36 |
# File 'lib/textutils/page.rb', line 31 def self.create( path, opts={} ) ## todo: check if 'w' is good enough?? do NOT need to add + page = self.new( path, 'w+', opts ) yield( page ) page.close end |
.open(path, mode, opts = {}) {|page| ... } ⇒ Object
convenience helper; use like:
Page.open() do |page|
page.write( text )
page.write( text )
end
25 26 27 28 29 |
# File 'lib/textutils/page.rb', line 25 def self.open( path, mode, opts={} ) page = self.new( path, mode, opts ) yield( page ) page.close end |
.update(path, opts = {}) {|page| ... } ⇒ Object
38 39 40 41 42 43 |
# File 'lib/textutils/page.rb', line 38 def self.update( path, opts={} ) ## todo: check if 'a' is good enough?? do NOT need to add + page = self.new( path, 'a+', opts ) yield( page ) page.close end |
Instance Method Details
#close ⇒ Object
61 62 63 |
# File 'lib/textutils/page.rb', line 61 def close @file.close end |
#write(text) ⇒ Object
57 58 59 |
# File 'lib/textutils/page.rb', line 57 def write( text ) @file.write( text ) end |