Class: WidgetList::Utils

Inherits:
Object show all
Defined in:
lib/widget_list/utils.rb

Class Method Summary collapse

Class Method Details

.build_query_string(args) ⇒ Object

BuildQueryString



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/widget_list/utils.rb', line 25

def self.build_query_string(args)
  q = []
  args.each { |k,v|
    if v.class.name == 'Hash'
      q << {k => v}.to_params
    else
      q << k.to_s + '=' + CGI.escape(URI.decode(v.to_s))
    end
  }
  q.join('&')
end

.build_url(page = '', args = {}, append_get = false) ⇒ Object

BuildUrl



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/widget_list/utils.rb', line 39

def self.build_url(page='',args = {}, append_get=false)
  qs = build_query_string(args)
  getvars = ''
  if append_get && $_REQUEST
    getvars = build_query_string($_REQUEST)
  end

  unless page =~ /\?/
    "#{page}?" + qs + '&' + getvars
  else
    "#{page}" + qs + '&' + getvars
  end
end

.date?(object) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/widget_list/utils.rb', line 11

def self.date?(object)
  true if Date.parse(object) rescue false
end

.fill(tags = {}, template = '') ⇒ Object

Fill



54
55
56
57
58
59
60
# File 'lib/widget_list/utils.rb', line 54

def self.fill(tags = {}, template = '')
  tpl = template.dup
  tags.each { |k,v|
    tpl = tpl.gsub(k.to_s,v.to_s)
  }
  tpl
end

.json_encode(arr, return_string = false) ⇒ Object

JsonEncode



16
17
18
19
20
21
22
# File 'lib/widget_list/utils.rb', line 16

def self.json_encode(arr,return_string = false)
  if return_string
    p JSON.generate(arr)
  else
    JSON.generate(arr)
  end
end

.numeric?(object) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/widget_list/utils.rb', line 7

def self.numeric?(object)
  true if Float(object) rescue false
end

.test_allObject

test_all



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
# File 'lib/widget_list/utils.rb', line 63

def self.test_all
  output_final = ''
  output_final += "JsonEncode\n<br/>\n<br/>"

  a = { }
  a['asdfasdf'] = 'asfd'
  a[:test] = 1234
  a[2153125] = nil
  output_final += Utils.json_encode(a)


  output_final += "\n<br/>\n<br/>BuildQueryString\n<br/>\n<br/>"

  a = { }
  a['asdfasdf'] = 'asdf asdfj ajskdfhasdf'
  a['dave'] = 'a)(J#(*J@T2p2kfasdfa fas %20fj ajskdfhasdf'
  output_final += Utils.build_query_string(a)


  output_final += "\n<br/>\n<br/>BuildUrl\n<br/>\n<br/>"


  output_final += Utils.build_url('page.php?',a)


  output_final += "\n<br/>\n<br/>Fill\n<br/>\n<br/>"

  output_final += Utils.fill({'<!--CONTENT-->'=>'dave','<!--TITLE-->'=>'the title'},'<!--TITLE--> ---------   <!--CONTENT-->')
end