Class: Documentize::Documentize

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

Constant Summary collapse

REGEX =
{
  ext:         /\.rb$|\.ru$/,
  shbang:      /^#!.*?ruby$/
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ Documentize

Returns a new instance of Documentize.



18
19
20
21
22
# File 'lib/documentize.rb', line 18

def initialize(file_name)
  @file = load_file(file_name)
  @collector = Collector.new
  @informator = Informator.new
end

Instance Attribute Details

#collectorObject (readonly)

Returns the value of attribute collector.



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

def collector
  @collector
end

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

#headerObject (readonly)

Returns the value of attribute header.



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

def header
  @header
end

#informatorObject (readonly)

Returns the value of attribute informator.



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

def informator
  @informator
end

#treeObject (readonly)

Returns the value of attribute tree.



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

def tree
  @tree
end

Instance Method Details

#load_file(file_name) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
# File 'lib/documentize.rb', line 24

def load_file(file_name)
  file = File.readlines(file_name).map {|line| line.strip} - [""]
  raise ArgumentError unless valid?(file_name, file[0])
  file
end

#runObject



30
31
32
33
34
35
# File 'lib/documentize.rb', line 30

def run
  @tree, @header = collector.run(@file)
  informator.gen_info(tree)
  informator.clear_screen
  Printer.print_with_docs(tree)
end