safai 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/safai/address.rb +18 -10
- data/lib/safai/clean.rb +10 -0
- data/lib/safai/gravatar.rb +15 -0
- data/lib/safai/spreadsheet.rb +1 -1
- data/lib/safai.rb +75 -1
- metadata +3 -1
data/lib/safai/address.rb
CHANGED
@@ -32,29 +32,37 @@ class Safai::Address
|
|
32
32
|
str = (u.addressline.blank? ? "" : u.addressline + ", ")
|
33
33
|
str = str + (u.city.blank? ? "" : u.city + ", ")
|
34
34
|
str = str + (u.zipcode.blank? ? "" : u.zipcode + ", ")
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
c = Safai::Address.country_to_s(u.country_code)
|
36
|
+
s = Safai::Address.state_to_s(u.country_code, u.subregion_code)
|
37
|
+
str = str + (s.blank? ? "" : s + ", ")
|
38
|
+
str = str + (c.blank? ? "" : c)
|
39
39
|
return str
|
40
40
|
end
|
41
41
|
|
42
42
|
def self.gist(u)
|
43
43
|
str = ""
|
44
44
|
str = (u.city.blank? ? "" : u.city + ", ")
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
c = Safai::Address.country_to_s(u.country_code)
|
46
|
+
s = Safai::Address.state_to_s(u.country_code, u.subregion_code)
|
47
|
+
str = str + (s.blank? ? "" : s + ", ")
|
48
|
+
str = str + (c.blank? ? "" : c)
|
49
49
|
return str
|
50
50
|
end
|
51
51
|
|
52
|
+
def self.gist_no_city(u)
|
53
|
+
str = ""
|
54
|
+
c = Safai::Address.country_to_s(u.country_code)
|
55
|
+
s = Safai::Address.state_to_s(u.country_code, u.subregion_code)
|
56
|
+
str = str + (s.blank? ? "" : s + ", ")
|
57
|
+
str = str + (c.blank? ? "" : c)
|
58
|
+
return str
|
59
|
+
end
|
52
60
|
|
53
61
|
def self.map(u, h=300, w=95)
|
54
62
|
str = ""
|
55
63
|
str = (u.city.blank? ? "" : u.city + "++")
|
56
|
-
|
57
|
-
|
64
|
+
c = Safai::Address.country_to_s(u.country_code)
|
65
|
+
str = str + (c.blank? ? "" : c)
|
58
66
|
return str == "" ? nil : "https://maps.google.com/maps/api/staticmap?visible=#{str}&size=#{h.to_s}x#{w.to_s}&sensor=false&maptype=terrain&markers=size:small|color:red|#{str}"
|
59
67
|
end
|
60
68
|
|
data/lib/safai/clean.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class Safai::Gravatar
|
2
|
+
|
3
|
+
def self.dp(email, size=20)
|
4
|
+
email = email.nil? ? "" : email
|
5
|
+
identifier = Digest::MD5.hexdigest(email.downcase)
|
6
|
+
return "http://gravatar.com/avatar/#{identifier}.png?s=#{size}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.profile(email)
|
10
|
+
email = email.nil? ? "" : email
|
11
|
+
identifier = Digest::MD5.hexdigest(email.downcase)
|
12
|
+
return "http://gravatar.com/#{identifier}"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/lib/safai/spreadsheet.rb
CHANGED
data/lib/safai.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
class Safai
|
2
2
|
|
3
|
+
#======================================
|
4
|
+
|
3
5
|
module Helpers
|
6
|
+
|
4
7
|
def f(ff)
|
5
8
|
sprintf("%0.02f", ff)
|
6
9
|
end
|
@@ -13,11 +16,82 @@ class Safai
|
|
13
16
|
return "" if i.blank?
|
14
17
|
i.year == Time.now.year ? i.strftime("%d-%b") : i.strftime("%d-%b-%Y")
|
15
18
|
end
|
19
|
+
|
20
|
+
def location_summary(u)
|
21
|
+
return Safai::Address.to_s(u)
|
22
|
+
end
|
23
|
+
|
24
|
+
def location_summary_short(u)
|
25
|
+
return Safai::Address.gist(u)
|
26
|
+
end
|
27
|
+
|
28
|
+
def location_map(u)
|
29
|
+
return Safai::Address.map(u, 300, 95)
|
30
|
+
end
|
31
|
+
|
32
|
+
def amt(c, amount)
|
33
|
+
amount = sprintf("%0.02f", amount)
|
34
|
+
return c == "USD" ? "$#{amount.to_s}" : "Rs.#{amount.to_s}"
|
35
|
+
end
|
36
|
+
|
16
37
|
end
|
17
38
|
|
39
|
+
#======================================
|
40
|
+
|
41
|
+
module DeviseHelpers
|
42
|
+
|
43
|
+
def resource_name
|
44
|
+
:user
|
45
|
+
end
|
46
|
+
|
47
|
+
def resource
|
48
|
+
@resource ||= User.new
|
49
|
+
end
|
50
|
+
|
51
|
+
def devise_mapping
|
52
|
+
@devise_mapping ||= Devise.mappings[:user]
|
53
|
+
end
|
54
|
+
|
55
|
+
#DEVISE end
|
56
|
+
|
57
|
+
def devise_error_messages!
|
58
|
+
flash_alerts = []
|
59
|
+
error_key = 'errors.messages.not_saved'
|
60
|
+
|
61
|
+
if !flash.empty?
|
62
|
+
flash_alerts.push(flash[:error]) if flash[:error]
|
63
|
+
flash_alerts.push(flash[:alert]) if flash[:alert]
|
64
|
+
flash_alerts.push(flash[:notice]) if flash[:notice]
|
65
|
+
error_key = 'devise.failure.invalid'
|
66
|
+
end
|
67
|
+
|
68
|
+
return "" if resource.errors.empty? && flash_alerts.empty?
|
69
|
+
errors = resource.errors.empty? ? flash_alerts : resource.errors.full_messages
|
70
|
+
|
71
|
+
messages = errors.map { |msg| content_tag(:li, msg) }.join
|
72
|
+
sentence = I18n.t(error_key, :count => errors.count,
|
73
|
+
:resource => resource.class.model_name.human.downcase)
|
74
|
+
|
75
|
+
html = <<-HTML
|
76
|
+
<div id="error_explanation">
|
77
|
+
<h2>#{sentence}</h2>
|
78
|
+
<ul>#{messages}</ul>
|
79
|
+
</div>
|
80
|
+
HTML
|
81
|
+
|
82
|
+
html.html_safe
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
#======================================
|
88
|
+
|
18
89
|
end
|
19
90
|
|
20
91
|
require 'safai/spreadsheet'
|
21
92
|
require 'safai/address'
|
22
93
|
require 'safai/regex'
|
23
|
-
|
94
|
+
require 'safai/clean'
|
95
|
+
require 'safai/gravatar'
|
96
|
+
ActionView::Base.send :include, Safai::Helpers
|
97
|
+
ActionView::Base.send :include, Safai::DeviseHelpers
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: safai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -37,6 +37,8 @@ files:
|
|
37
37
|
- lib/safai/spreadsheet.rb
|
38
38
|
- lib/safai/regex.rb
|
39
39
|
- lib/safai/address.rb
|
40
|
+
- lib/safai/clean.rb
|
41
|
+
- lib/safai/gravatar.rb
|
40
42
|
homepage: http://rubygems.org/gems/safai
|
41
43
|
licenses: []
|
42
44
|
post_install_message:
|