Module: Baiduserp::Helper

Defined in:
lib/baiduserp/helper.rb

Class Method Summary collapse

Class Method Details

.get_content_safe(noko) ⇒ Object

get content safe from nokogiri search reasult



5
6
7
8
9
# File 'lib/baiduserp/helper.rb', line 5

def get_content_safe(noko)
  return nil if noko.nil?
  return nil if noko.empty?
  noko.first.content.strip
end

.parse_data_click(str) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/baiduserp/helper.rb', line 11

def parse_data_click(str)
  JSON.parse(str
               .gsub("'",'"')
               .gsub(/({|,)([a-zA-Z0-9_]+):/, '\1"\2":')
               #.gsub(/'*([a-zA-Z0-9_]+)'*:/, '"\1":')
               #.gsub(/:'([^(',\")]*)'(,|})/,':"\1"\2')
             )
end