class Madman::Document
Attributes
filename[R]
text[RW]
yaml_mode[RW]
Public Class Methods
from_file(file)
click to toggle source
# 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
new(text, filename=nil)
click to toggle source
# File lib/madman/document.rb, line 21 def initialize(text, filename=nil) @text = text @filename = filename end
Public Instance Methods
render(renderer=:default)
click to toggle source
# 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?()
click to toggle source
# File lib/madman/document.rb, line 34 def rtl? detector.direction(text[0..200]) == 'rtl' end
save(save_as=nil)
click to toggle source
# 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
Private Instance Methods
detector()
click to toggle source
# File lib/madman/document.rb, line 46 def detector @detector ||= StringDirection::Detector.new :dominant end
renderers()
click to toggle source
# File lib/madman/document.rb, line 50 def renderers Renderers.available_renderers end