Class: Madman::Document
- Inherits:
-
Object
- Object
- Madman::Document
- Includes:
- Injector
- Defined in:
- lib/madman/document.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#text ⇒ Object
Returns the value of attribute text.
-
#yaml_mode ⇒ Object
Returns the value of attribute yaml_mode.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(text, filename = nil) ⇒ Document
constructor
A new instance of Document.
- #render(renderer = :default) ⇒ Object
- #rtl? ⇒ Boolean
- #save(save_as = nil) ⇒ Object
Methods included from Injector
Constructor Details
#initialize(text, filename = nil) ⇒ Document
Returns a new instance of Document.
21 22 23 24 |
# File 'lib/madman/document.rb', line 21 def initialize(text, filename=nil) @text = text @filename = filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
8 9 10 |
# File 'lib/madman/document.rb', line 8 def filename @filename end |
#text ⇒ Object
Returns the value of attribute text.
9 10 11 |
# File 'lib/madman/document.rb', line 9 def text @text end |
#yaml_mode ⇒ Object
Returns the value of attribute yaml_mode.
9 10 11 |
# File 'lib/madman/document.rb', line 9 def yaml_mode @yaml_mode end |
Class Method Details
.from_file(file) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/madman/document.rb', line 11 def self.from_file(file) if File.extname(file) == '.yml' result = new YAML.load_file(file), file result.yaml_mode = true result else new File.read(file), file end end |
Instance Method Details
#render(renderer = :default) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/madman/document.rb', line 26 def render(renderer=:default) if yaml_mode renderers[:yaml].render text, title: File.basename(filename, '.yml') else renderers[renderer].render text end end |
#rtl? ⇒ Boolean
34 35 36 |
# File 'lib/madman/document.rb', line 34 def rtl? detector.direction(text[0..200]) == 'rtl' end |
#save(save_as = nil) ⇒ Object
38 39 40 41 42 |
# File 'lib/madman/document.rb', line 38 def save(save_as=nil) save_as ||= filename raise ArgumentError, "No filename provided" unless save_as File.write save_as, text end |