Class: RTFM::GroffString

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str = "") ⇒ GroffString

Returns a new instance of GroffString.



12
13
14
# File 'lib/rtfm/groffstring.rb', line 12

def initialize(str = "")
  @source = str.dup
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



41
42
43
# File 'lib/rtfm/groffstring.rb', line 41

def method_missing(meth, *args, &block)
  add_line ".#{meth} #{args.join(" ")}"
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



4
5
6
# File 'lib/rtfm/groffstring.rb', line 4

def source
  @source
end

Class Method Details

.groffify(str = "") {|out| ... } ⇒ Object

Yields:

  • (out)


6
7
8
9
10
# File 'lib/rtfm/groffstring.rb', line 6

def self.groffify(str = "")
  out = self.new(str)
  yield out
  out.to_s
end

Instance Method Details

#add_line(line) ⇒ Object Also known as: <<



24
25
26
# File 'lib/rtfm/groffstring.rb', line 24

def add_line(line)
  source << line.rstrip << "\n"
end

#put_nameObject



33
34
35
# File 'lib/rtfm/groffstring.rb', line 33

def put_name
  self.Nm
end

#reference(page, section = nil) ⇒ Object



37
38
39
# File 'lib/rtfm/groffstring.rb', line 37

def reference(page, section = nil)
  self.Xr page, (section || "")
end

#rstripObject



20
21
22
# File 'lib/rtfm/groffstring.rb', line 20

def rstrip
  source.rstrip
end

#section(section) ⇒ Object



29
30
31
# File 'lib/rtfm/groffstring.rb', line 29

def section(section)
  self.Sh section.upcase
end

#to_sObject



16
17
18
# File 'lib/rtfm/groffstring.rb', line 16

def to_s
  source
end