Class: OboParser::Tokens::TagValuePair
Overview
Token needs simplification, likely through creating additional tokens for quoted qualifiers, optional modifiers ({}), and the creation of individual tokens for individual tags that don’t conform to the pattern used for def: tags. The code can’t presently handle escaped characters (like ,), as bizzarely found in some OBO files.
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#qualifier ⇒ Object
readonly
Returns the value of attribute qualifier.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#xrefs ⇒ Object
readonly
Returns the value of attribute xrefs.
Attributes inherited from Token
Instance Method Summary collapse
-
#initialize(str) ⇒ TagValuePair
constructor
A new instance of TagValuePair.
Constructor Details
#initialize(str) ⇒ TagValuePair
Returns a new instance of TagValuePair.
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/tokens.rb', line 26 def initialize(str) str.strip! tag, value = str.split(':',2) value.strip! if tag == 'comment' @tag = tag.strip @value = value.strip return end @xrefs = [] # Handle inline comments if value =~ /(\s+!\s*.+)\s*\n*\z/i @comment = $1 value.gsub!(@comment, '') @comment.strip! @comment.gsub!(/\A!\s*/, '') end value.strip! # Qualifier for the whole tag if value =~ /(\{[^{]*?\})\s*\n*\z/ @qualifier = $1 value.gsub!(@qualifier, '') @qualifier.strip! end value.strip! # Handle a xref list TODO: Tokenize if value =~ /(\[.*\])/i xref_list = $1 value.gsub!(xref_list, '') xref_list.strip! xref_list = xref_list[1..-2] # [] off qq = 0 # some failsafes while xref_list.length > 0 qq += 1 debugger if qq == 499 raise "#{xref_list}" if qq > 500 xref_list.gsub!(/\A\s*,\s*/, '') xref_list =~ /\A(.+?:[^\"|\{|\,]+)/i v = $1 if !(v == "") && !v.nil? v.strip! r = Regexp.escape v xref_list.gsub!(/\A#{r}\s*/, '') @xrefs.push(v) if !v.nil? end xref_list.strip! # A description if xref_list =~ /\A(\s*".*?")/i d = $1 r = Regexp.escape d xref_list.gsub!(/\A#{r}/, '') xref_list.strip! end # A optional modifier if xref_list =~ /\A(\s*\{[^\}]*?\})/ m = $1 r = Regexp.escape m xref_list.gsub!(/\A#{r}/, '') xref_list.strip! end xref_list.strip! end end value.strip! # At this point we still might have a '"foo" QUALIFIER' combination if value =~ /\A(\"[^\"]*\")\s+(.*)/ @value = $1.strip @qualifier = $2.strip if !$2.nil? else @value = value.strip end @value = @value[1..-2].strip if @value[0..0] == "\"" @tag = tag.strip @value.strip! end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
24 25 26 |
# File 'lib/tokens.rb', line 24 def comment @comment end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
24 25 26 |
# File 'lib/tokens.rb', line 24 def description @description end |
#qualifier ⇒ Object (readonly)
Returns the value of attribute qualifier.
24 25 26 |
# File 'lib/tokens.rb', line 24 def qualifier @qualifier end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
24 25 26 |
# File 'lib/tokens.rb', line 24 def tag @tag end |
#xrefs ⇒ Object (readonly)
Returns the value of attribute xrefs.
24 25 26 |
# File 'lib/tokens.rb', line 24 def xrefs @xrefs end |