Class: Text
- Inherits:
-
Object
- Object
- Text
- Defined in:
- lib/notroff/text.rb,
lib/yesroff/text.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
Returns the value of attribute attrs.
-
#string ⇒ Object
Returns the value of attribute string.
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #clone ⇒ Object
-
#initialize(t) ⇒ Text
constructor
A new instance of Text.
- #inspect ⇒ Object
- #length ⇒ Object
- #render(w) ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize(t) ⇒ Text
Returns a new instance of Text.
6 7 8 9 |
# File 'lib/notroff/text.rb', line 6 def initialize(initial_string, initial_attrs={}) @string = initial_string.to_str.clone @attrs = initial_attrs.clone end |
Instance Attribute Details
#attrs ⇒ Object
Returns the value of attribute attrs.
4 5 6 |
# File 'lib/notroff/text.rb', line 4 def attrs @attrs end |
#string ⇒ Object
Returns the value of attribute string.
4 5 6 |
# File 'lib/notroff/text.rb', line 4 def string @string end |
#text ⇒ Object
Returns the value of attribute text.
139 140 141 |
# File 'lib/yesroff/text.rb', line 139 def text @text end |
Class Method Details
.wrap_method(method_name) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/notroff/text.rb', line 11 def self.wrap_method(method_name) define_method method_name do |*args| result = @string.send(method_name, *args) return Text.new(result, attrs) if result.kind_of? String result end end |
.wrap_methods(method_names) ⇒ Object
19 20 21 |
# File 'lib/notroff/text.rb', line 19 def self.wrap_methods(method_names) method_names.each {|name| wrap_method(name)} end |
Instance Method Details
#==(other) ⇒ Object
33 34 35 36 |
# File 'lib/notroff/text.rb', line 33 def ==(other) return false unless other.kind_of? Text @string == other.string && @attrs == other.attrs end |
#[](name) ⇒ Object
25 26 27 |
# File 'lib/notroff/text.rb', line 25 def [](name) @attrs[name] end |
#[]=(name, value) ⇒ Object
29 30 31 |
# File 'lib/notroff/text.rb', line 29 def []=(name, value) @attrs[name] = value end |
#clone ⇒ Object
38 39 40 |
# File 'lib/notroff/text.rb', line 38 def clone Text.new(string, attrs) end |
#inspect ⇒ Object
51 52 53 |
# File 'lib/notroff/text.rb', line 51 def inspect "#{@string.inspect} :: #{@attrs.inspect}" end |
#length ⇒ Object
152 153 154 |
# File 'lib/yesroff/text.rb', line 152 def length @text.length end |
#render(w) ⇒ Object
145 146 147 148 149 150 |
# File 'lib/yesroff/text.rb', line 145 def render(w) text = @text.gsub(/@@/, '\@\@') text = text.gsub(/~~/, '\~\~') text = text.gsub(/!!/, '\!\!') w.text(text) end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/notroff/text.rb', line 47 def to_s @string end |
#to_str ⇒ Object
42 43 44 45 |
# File 'lib/notroff/text.rb', line 42 def to_str #puts "To string: #{@string.class} #{@string}" @string end |