Class: Rascut::Asdoc::Parser
- Inherits:
-
Object
- Object
- Rascut::Asdoc::Parser
- Defined in:
- lib/rascut/asdoc/parser.rb
Instance Attribute Summary collapse
-
#classname ⇒ Object
readonly
Returns the value of attribute classname.
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#package ⇒ Object
readonly
Returns the value of attribute package.
Instance Method Summary collapse
-
#initialize(source, logger = nil) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(source, logger = nil) ⇒ Parser
Returns a new instance of Parser.
11 12 13 14 15 16 17 18 19 |
# File 'lib/rascut/asdoc/parser.rb', line 11 def initialize(source, logger = nil) source = NKF::nkf('-m0 -w', source) @logger = logger || Logger.new(STDOUT) @logger.level = Logger::DEBUG @source = Hpricot(source) @methods = [] @package = nil @classname = nil end |
Instance Attribute Details
#classname ⇒ Object (readonly)
Returns the value of attribute classname.
20 21 22 |
# File 'lib/rascut/asdoc/parser.rb', line 20 def classname @classname end |
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
20 21 22 |
# File 'lib/rascut/asdoc/parser.rb', line 20 def methods @methods end |
#package ⇒ Object (readonly)
Returns the value of attribute package.
20 21 22 |
# File 'lib/rascut/asdoc/parser.rb', line 20 def package @package end |
Instance Method Details
#parse ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rascut/asdoc/parser.rb', line 22 def parse title = @source.at('title').inner_text @package = title.split('.')[0..-2].join('.') @classname = title.split('.')[-1].split(/\s/)[0] @logger.debug "parse: #{@package} #{@classname}" @source.search('td.summaryTableSignatureCol').each {|el| next if el.at('td.summaryTableInheritanceCol') || !el.at('a') begin method = { :href => el.at('a')['href'], :name => el.at('a').inner_text.strip, :code => el.search('div:not(.summaryTableDescription)').inner_text.strip.gsub("\n", ' '), } if summary = el.at('div.summaryTableDescription') s = summary.inner_text.strip.gsub("\n", ' ') if s[0..0] == '[' && s[-1..-1] == ']' method[:code] << " #{s}" method[:code].strip! else method[:summary] = s end end @methods << method rescue NoMethodError => e @logger.debug e. @logger.debug el.inner_text.strip.gsub("\n", ' ') end } @logger.debug "parse: #{@methods.length} methods found" end |