Class: NRWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/yesroff/nr_writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNRWriter

Returns a new instance of NRWriter.



4
5
6
7
8
9
10
# File 'lib/yesroff/nr_writer.rb', line 4

def initialize
  @bold_depth = 0
  @italic_depth = 0
  @code_depth = 0
  @text_style = :normal
  @single_line = false
end

Instance Attribute Details

#para_styleObject (readonly)

Returns the value of attribute para_style.



2
3
4
# File 'lib/yesroff/nr_writer.rb', line 2

def para_style
  @para_style
end

Instance Method Details

#end_boldObject



57
58
59
60
# File 'lib/yesroff/nr_writer.rb', line 57

def end_bold
  print "!!" if @bold_depth == 1
  @bold_depth -= 1
end

#end_codeObject



77
78
79
80
# File 'lib/yesroff/nr_writer.rb', line 77

def end_code
  print "@@ " if @code_depth == 1
  @code_depth -= 1
end

#end_italicObject



67
68
69
70
# File 'lib/yesroff/nr_writer.rb', line 67

def end_italic
  print "~~ " if @italic_depth == 1
  @italic_depth -= 1
end

#end_paragraphObject



37
38
39
40
41
42
43
44
45
# File 'lib/yesroff/nr_writer.rb', line 37

def end_paragraph
  puts
  if @single_line
    @para_style = :body
    @single_line = false
  elsif @para_style != :code && @para_style != :listing
    puts
  end
end

#indent(n) ⇒ Object



47
48
49
50
# File 'lib/yesroff/nr_writer.rb', line 47

def indent(n)
  log "indent #{n}"
  print (' ' * n)    
end

#special_style?Boolean

Returns:

  • (Boolean)


82
83
84
85
# File 'lib/yesroff/nr_writer.rb', line 82

def special_style?
  return true unless @para_style ==  :body
  @code_depth > 0 or @italic_depth > 0 or @bold_depth > 0
end

#split_text(t) ⇒ Object



87
88
89
90
# File 'lib/yesroff/nr_writer.rb', line 87

def split_text(t)
  return t if t.length < 80
  words = t.split(' ')
end

#start_boldObject



52
53
54
55
# File 'lib/yesroff/nr_writer.rb', line 52

def start_bold
  print "!!" if @bold_depth == 0
  @bold_depth += 1
end

#start_codeObject



72
73
74
75
# File 'lib/yesroff/nr_writer.rb', line 72

def start_code
  print "@@" if @code_depth == 0
  @code_depth += 1
end

#start_italicObject



62
63
64
65
# File 'lib/yesroff/nr_writer.rb', line 62

def start_italic
  print "~~" if @italic_depth == 0
  @italic_depth += 1
end

#switch_para_style(new_style, single_line) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/yesroff/nr_writer.rb', line 12

def switch_para_style(new_style, single_line)
  #end_paragraph
  return if new_style == @para_style
  print ".#{new_style}"
  if single_line
    print ' '
  else
    print "\n"
  end
  @para_style = new_style
  @single_line = single_line
end

#switch_text_style(new_style) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/yesroff/nr_writer.rb', line 25

def switch_text_style(new_style)
  log " <<switching to new style #{new_style}>>  "
  return if @text_style == new_style
  if @text_style != :normal
    toggle_text_style(@text_style)
  end
  if new_style != :normal
    toggle_text_style(new_style)
  end
  @text_style = new_style
end

#text(t) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/yesroff/nr_writer.rb', line 92

def text(t)
  log "==>Text #{t}"
  if special_style?
    print t
  else
    array = t.split(' ')
    line_len = 0
    array.each do |word|
      print word
      line_len += word.length
      if line_len > 70
        print "\n"
        line_len = 0
      else
        print " "
        line_len += 1
      end
    end
  end
end