Class: Cornell

Inherits:
Object
  • Object
show all
Includes:
Methadone::CLILogging
Defined in:
lib/papernote/formats/cornell.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Cornell

Returns a new instance of Cornell.



8
9
10
11
12
13
14
# File 'lib/papernote/formats/cornell.rb', line 8

def initialize(options={})
  @pdf = Prawn::Document.new(page_size: "A4", margin: 0)
  @pdf.line_width = 1
  (@width, @height) = @pdf.page.dimensions[2,3]
  debug("Dimensions are W: #{@width}, H: #{@height}")
  @options = { area: :graph, spacing: 8, color: "c0c0c0" }.merge(options)
end

Instance Method Details

#make_cue_area(mirror = false) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/papernote/formats/cornell.rb', line 46

def make_cue_area(mirror=false)
  debug("Cue area start")
  from = 0
  to = 64.mm
  if mirror
    from = @width - from
    to = @width - to
  end
  @pdf.stroke do
    @pdf.horizontal_line from, to, at: 55.mm
    @pdf.vertical_line 55.mm, @height, at: to
  end
  debug("Cue area end")
end

#make_grid_area(type, mirror = false) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/papernote/formats/cornell.rb', line 87

def make_grid_area(type, mirror=false)
  case type
  when :graph
    plot_graph(@options[:spacing], @options[:color], mirror)
  when :ruled
    plot_ruled(@options[:spacing], @options[:color], mirror)
  end
end

#make_holesObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/papernote/formats/cornell.rb', line 30

def make_holes
  holes = @options[:holes] || 0
  holes = Integer(holes)
  if holes > 0
    from_left = 11.mm
    hole_radius = 5.mm / 2
    margin = hole_radius + ((296.mm - ((holes -1) * 80.mm)) / 2)
    debug("Hole margin is #{margin}")
    debug("Hole gap is #{80.mm}")
    margin.step(@height, 80.mm) do |h|
      debug("Hole at #{[from_left, h]}, radius #{hole_radius}")
      @pdf.stroke_circle([from_left, h], hole_radius)
    end
  end
end

#make_notes_area(mirror = false) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/papernote/formats/cornell.rb', line 72

def make_notes_area(mirror=false)
  left = 65.mm
  right = 210.mm
  if mirror
    left = @width - left
    right = @width - right
  end

  @pdf.stroke do
    @pdf.vertical_line 55.mm, @height, at: left
    @pdf.horizontal_line left, right, at: 55.mm
  end
  make_grid_area(@options[:area].to_sym, mirror)
end

#make_pageObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/papernote/formats/cornell.rb', line 16

def make_page
  make_cue_area
  make_title_area
  make_notes_area
  make_review_area
  make_holes
  @pdf.start_new_page
  make_title_area(:mirror)
  make_cue_area(:mirror)
  make_notes_area(:mirror)
  make_review_area(:mirror)
  @pdf
end

#make_review_area(mirror = false) ⇒ Object



132
133
134
135
136
# File 'lib/papernote/formats/cornell.rb', line 132

def make_review_area(mirror=false)
  @pdf.stroke do
    @pdf.horizontal_line 0, 210.mm, at: 54.mm
  end
end

#make_title_area(mirror = false) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/papernote/formats/cornell.rb', line 61

def make_title_area(mirror=false)
  x_origin = mirror ? 15.mm : 64.mm
  align = mirror ? :left : :right
  @pdf.bounding_box([x_origin, 295.mm], width: 130.mm, height: 27.mm) do
    @pdf.move_cursor_to 20.mm
    title_area_text(@options[:title], align)
    title_area_text(@options[:name], align)
    title_area_text(@options[:date], 9, align)
  end
end

#plot_graph(step, color, mirror = false) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/papernote/formats/cornell.rb', line 96

def plot_graph(step, color, mirror = false)
  plot_ruled(step, color, mirror)
  left = 66.mm
  right = 205.mm
  if mirror
    left = @width - left
    right = @width - right
    step = -step
  end
  old_color = @pdf.stroke_color
  @pdf.stroke do
    @pdf.stroke_color = color
    (left + step.mm).step(right, step.mm) do |pos|
      @pdf.vertical_line 265.mm, 61.mm, at: pos
    end
  end
  @pdf.stroke_color = old_color
end

#plot_ruled(step, color, mirror = false) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/papernote/formats/cornell.rb', line 115

def plot_ruled(step, color, mirror=false)
  old_color = @pdf.stroke_color
  left = 66.mm
  right = 205.mm
  if mirror
    left = @width - left
    right = @width - right
  end
  @pdf.stroke do
    @pdf.stroke_color = color
    265.mm.step((61).mm, -step.mm) do |pos|
      @pdf.horizontal_line left, right, at: pos
    end
  end
  @pdf.stroke_color = old_color
end