Class: SchemaRD::DefaultTableCommentParser
- Inherits:
-
Object
- Object
- SchemaRD::DefaultTableCommentParser
- Defined in:
- lib/schemard/rdoc_parser.rb
Instance Method Summary collapse
- #description ⇒ Object
- #has_description? ⇒ Boolean
- #has_localized_name? ⇒ Boolean
- #has_relation_of?(rel_type) ⇒ Boolean
-
#initialize(comment_text) ⇒ DefaultTableCommentParser
constructor
A new instance of DefaultTableCommentParser.
- #localized_name ⇒ Object
- #relation_of(rel_type) ⇒ Object
Constructor Details
#initialize(comment_text) ⇒ DefaultTableCommentParser
Returns a new instance of DefaultTableCommentParser.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/schemard/rdoc_parser.rb', line 30 def initialize(comment_text) @hash = { relations: {} } @hash[:description] = comment_text.split("\n").map(&:strip).map{|line| if line =~ /^name\:\:/ || line =~ /^localized_name\:\:/ @hash[:localized_name] = line.match(/^[^:]*name\:\:(.+)$/)[1].strip next end %w(belongs_to has_many has_one).each do |rel_type| if line =~ /^#{rel_type}\:\:/ tables = line.match(/^#{rel_type}\:\:(.+)$/)[1].split(",").map(&:strip).select{|s| s != "" } @hash[:relations][rel_type.to_sym] = tables unless tables.empty? line = nil # skip this line (by compact) end end line }.compact.join("\n") end |
Instance Method Details
#description ⇒ Object
56 57 58 |
# File 'lib/schemard/rdoc_parser.rb', line 56 def description @hash[:description] end |
#has_description? ⇒ Boolean
53 54 55 |
# File 'lib/schemard/rdoc_parser.rb', line 53 def has_description? !!@hash[:description] end |
#has_localized_name? ⇒ Boolean
47 48 49 |
# File 'lib/schemard/rdoc_parser.rb', line 47 def has_localized_name? @hash[:localized_name] && @hash[:localized_name] != "" end |
#has_relation_of?(rel_type) ⇒ Boolean
59 60 61 |
# File 'lib/schemard/rdoc_parser.rb', line 59 def has_relation_of?(rel_type) !!@hash[:relations][rel_type] end |
#localized_name ⇒ Object
50 51 52 |
# File 'lib/schemard/rdoc_parser.rb', line 50 def localized_name @hash[:localized_name] end |
#relation_of(rel_type) ⇒ Object
62 63 64 |
# File 'lib/schemard/rdoc_parser.rb', line 62 def relation_of(rel_type) @hash[:relations][rel_type] end |