Class: Ld::Views

Inherits:
Object
  • Object
show all
Defined in:
lib/ld/project/views.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, models) ⇒ Views



4
5
6
7
8
# File 'lib/ld/project/views.rb', line 4

def initialize root, models
  @root = root
  @models = models
  parse
end

Instance Attribute Details

#headingsObject

Returns the value of attribute headings.



2
3
4
# File 'lib/ld/project/views.rb', line 2

def headings
  @headings
end

#rowsObject

Returns the value of attribute rows.



2
3
4
# File 'lib/ld/project/views.rb', line 2

def rows
  @rows
end

Instance Method Details

#find(model_name) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/ld/project/views.rb', line 19

def find model_name
  @view_dirs.each do |view_dir|
    if view_dir.name == model_name.pluralize
      return Ld::View.new view_dir
    end
  end
  nil
end

#parseObject



10
11
12
13
14
15
16
17
# File 'lib/ld/project/views.rb', line 10

def parse
  @rows = @root.find('app/views').search_regexp(/.html/).map{|v|
    dir_name = v.parent.name
    model_name = @models.models.include?(dir_name.singularize) ? dir_name.singularize : nil
    [model_name,v.lines.size,dir_name,v.name,v.path]
  }.sort{|a,b| b[1] <=> a[1]}
  @headings = ['所属模型名','行数','文件夹名','文件名','path']
end