Class: LOCat::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/locat/template.rb

Constant Summary collapse

DIRECTORY =
File.dirname(__FILE__) + '/template'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(counter, metadata) ⇒ Template

Returns a new instance of Template.



10
11
12
13
# File 'lib/locat/template.rb', line 10

def initialize(counter, )
  @counter  = counter
  @metadata = 
end

Instance Attribute Details

#counterObject (readonly)

Returns the value of attribute counter.



16
17
18
# File 'lib/locat/template.rb', line 16

def counter
  @counter
end

#metadataObject (readonly)

Returns the value of attribute metadata.



19
20
21
# File 'lib/locat/template.rb', line 19

def 
  @metadata
end

Instance Method Details

#countsObject



27
28
29
# File 'lib/locat/template.rb', line 27

def counts
  counter.counts
end

#javascriptObject



75
76
77
78
79
# File 'lib/locat/template.rb', line 75

def javascript
  @javascript ||= (
    File.read(File.join(DIRECTORY, 'javascript.js'))
  )
end

#render(template) ⇒ Object



82
83
84
85
86
# File 'lib/locat/template.rb', line 82

def render(template)
  file = File.join(DIRECTORY, template + '.rhtml')
  erb  = ERB.new(File.read(file))
  erb.result(__binding__)
end

#scm?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/locat/template.rb', line 65

def scm?
  File.directory?('.git')
end

#table_locObject



32
33
34
# File 'lib/locat/template.rb', line 32

def table_loc
  counter.loc
end

#table_pcntObject Also known as: table_percentages



37
38
39
# File 'lib/locat/template.rb', line 37

def table_pcnt
  counter.percent
end

#table_ratioObject



45
46
47
# File 'lib/locat/template.rb', line 45

def table_ratio
  counter.ratio
end

#table_scmObject



50
51
52
# File 'lib/locat/template.rb', line 50

def table_scm
  counter.scm
end

#titleObject



70
71
72
# File 'lib/locat/template.rb', line 70

def title
  "The LOCat on " + (['title'] || File.basename(Dir.pwd))
end

#to_jsonObject



55
56
57
58
59
60
61
62
# File 'lib/locat/template.rb', line 55

def to_json
  h = {}
  h[:loc]   = table_loc
  h[:pcnt]  = table_pcnt
  h[:ratio] = table_ratio
  h[:scm]   = table_scm if scm?
  h.to_json
end

#totalObject



22
23
24
# File 'lib/locat/template.rb', line 22

def total
  counter.total
end