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



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

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 + '=' + URI.encode(URI.decode(v.to_s))
    end
  }
  q.join('&')
end

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

BuildUrl



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

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)


9
10
11
# File 'lib/widget_list/utils.rb', line 9

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

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

Fill



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

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



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

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)


5
6
7
# File 'lib/widget_list/utils.rb', line 5

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

.test_allObject

test_all



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

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