Class: Tokenize
- Inherits:
-
Object
- Object
- Tokenize
- Defined in:
- lib/ieparser_extension.rb
Defined Under Namespace
Classes: Tokagram
Instance Attribute Summary collapse
-
#tokenized_expression ⇒ Object
readonly
Returns the value of attribute tokenized_expression.
Instance Method Summary collapse
- #get_element_from_token ⇒ Object
-
#initialize(xpath_expression) ⇒ Tokenize
constructor
A new instance of Tokenize.
- #populate ⇒ Object
-
#strip_out_id_if_present ⇒ Object
~ end.
- #token_has_finder_info? ⇒ Boolean
- #tokenize_by_divider ⇒ Object
- #write_finder_information ⇒ Object
- #write_path_information ⇒ Object
Constructor Details
Instance Attribute Details
#tokenized_expression ⇒ Object (readonly)
Returns the value of attribute tokenized_expression.
311 312 313 |
# File 'lib/ieparser_extension.rb', line 311 def tokenized_expression @tokenized_expression end |
Instance Method Details
#get_element_from_token ⇒ Object
393 394 395 396 397 398 399 400 401 402 |
# File 'lib/ieparser_extension.rb', line 393 def get_element_from_token @tokenized_expression[-1].match(/(\w*)\[.*\]$/) element = $1.to_s if element.empty? result = nil else result = element end result end |
#populate ⇒ Object
408 409 410 411 412 413 414 415 |
# File 'lib/ieparser_extension.rb', line 408 def populate tokenize_by_divider #~ expand_occurrences strip_out_id_if_present write_finder_information write_path_information @tokagram end |
#strip_out_id_if_present ⇒ Object
~ end
345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/ieparser_extension.rb', line 345 def strip_out_id_if_present split = @tokenized_expression.first.split('#') if split.size == 2 id = split[1] @tokagram.tag_id = id #remove the id from the array @tokenized_expression.shift else @tokagram.tag_id = nil end @tokagram end |
#token_has_finder_info? ⇒ Boolean
404 405 406 |
# File 'lib/ieparser_extension.rb', line 404 def token_has_finder_info? get_element_from_token != nil end |
#tokenize_by_divider ⇒ Object
318 319 320 321 |
# File 'lib/ieparser_extension.rb', line 318 def tokenize_by_divider @tokenized_expression = @xpath_expression.split(">").collect{|element| element.gsub(/^\s/,"").gsub(/\s$/,"")} end |
#write_finder_information ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/ieparser_extension.rb', line 358 def write_finder_information if token_has_finder_info? detail = @tokenized_expression[-1] detail.match(/^(\w+)\[(.+)\]$/) element = $1.to_s finder_detail = $2.to_s finder_detail.match(/^(.+\w)(=.)"(.+)"$/) criteria = $1.to_s selector = $2.to_s value = $3.to_s finder = { :element => element, :criteria => criteria.gsub("@",""), #remove the @ from attribute if has one :value => value, :selector => selector } @tokagram.finder = finder end end |
#write_path_information ⇒ Object
383 384 385 386 387 388 389 390 391 |
# File 'lib/ieparser_extension.rb', line 383 def write_path_information # remove the rest of the search criteria from the last array element if it has any element = get_element_from_token if token_has_finder_info? @tokenized_expression.pop @tokenized_expression << element end @tokagram.path = @tokenized_expression end |