Class: OverpassDoc::Query
- Inherits:
-
Object
- Object
- OverpassDoc::Query
- Defined in:
- lib/overpass-doc/query.rb
Constant Summary collapse
- PATTERN =
%r{(?<multi>/\*(?<multi_content>(.|\n)*?)?\*/)|(?<error>/\*(.*)?)}
- ANNOTATIONS =
{ :author => { :multi => true }, :see => { :multi => true }, :tags => { :multi => true }, :title => { :multi => false }, }
Instance Attribute Summary collapse
-
#package ⇒ Object
readonly
Returns the value of attribute package.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#raw_query ⇒ Object
readonly
Returns the value of attribute raw_query.
Instance Method Summary collapse
- #description(html = false) ⇒ Object
- #extract_annotation(line) ⇒ Object
-
#initialize(path, query, package = {}) ⇒ Query
constructor
A new instance of Query.
- #output_filename ⇒ Object
- #query_string ⇒ Object
Constructor Details
#initialize(path, query, package = {}) ⇒ Query
Returns a new instance of Query.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/overpass-doc/query.rb', line 28 def initialize(path, query, package={}) ANNOTATIONS.each do |var, config| if config[:multi] instance_variable_set( "@#{var}", [] ) else instance_variable_set( "@#{var}", "" ) end end @path = path @query = query @raw_query = query @title = @path @description = "" ["author", "tag"].each do |annotation| if package[annotation] instance_variable_set( "@#{annotation}", package[annotation]) end end parseQuery() end |
Instance Attribute Details
#package ⇒ Object (readonly)
Returns the value of attribute package.
5 6 7 |
# File 'lib/overpass-doc/query.rb', line 5 def package @package end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/overpass-doc/query.rb', line 5 def path @path end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
5 6 7 |
# File 'lib/overpass-doc/query.rb', line 5 def query @query end |
#raw_query ⇒ Object (readonly)
Returns the value of attribute raw_query.
5 6 7 |
# File 'lib/overpass-doc/query.rb', line 5 def raw_query @raw_query end |
Instance Method Details
#description(html = false) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/overpass-doc/query.rb', line 54 def description(html=false) if html renderer = Redcarpet::Render::HTML.new({}) markdown = Redcarpet::Markdown.new(renderer, {}) return markdown.render(@description) end @description end |
#extract_annotation(line) ⇒ Object
67 68 69 70 71 |
# File 'lib/overpass-doc/query.rb', line 67 def extract_annotation(line) matches = line.lstrip.match(/^@([a-zA-Z]+) *(.+)$/i) return nil unless matches return matches[1], matches[2] end |
#output_filename ⇒ Object
50 51 52 |
# File 'lib/overpass-doc/query.rb', line 50 def output_filename return "#{path.gsub(".op", "")}.html" end |
#query_string ⇒ Object
63 64 65 |
# File 'lib/overpass-doc/query.rb', line 63 def query_string CGI::escape( @query ) end |