pyk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ebb0bcf371c31f6930fb71ebea88b26675e7d6e
4
+ data.tar.gz: 3b2c11eb574660471ad80c48f46a298bc0a5801c
5
+ SHA512:
6
+ metadata.gz: 1eeeb8db88ad248923b62fd6088a3063cd694a55a4cd693fffd5bb6fe8f54dd94f0f71feb88aa912fe8f604be644820d3def57948dca95119ddd5245e0ece31d
7
+ data.tar.gz: b66df064c7970bc269100a4798a74d0748162143df631f8e639a494c101809a71642e4fb8f88cb5f0ba65f8ac525f953e021ec5b13131c15e734689d42e8362f
@@ -0,0 +1,71 @@
1
+ class Pyk::Address
2
+
3
+ #GEMS USED
4
+ require 'carmen'
5
+ include Carmen
6
+
7
+ def self.country_to_s(country_iso2)
8
+ if !country_iso2.nil?
9
+ cobj = Country.coded(country_iso2)
10
+ if !cobj.blank?
11
+ return cobj.name
12
+ end
13
+ end
14
+ return ""
15
+ end
16
+
17
+ def self.state_to_s(country_iso2, state_iso2)
18
+ if !country_iso2.nil? and !state_iso2.nil?
19
+ cobj = Country.coded(country_iso2)
20
+ if !cobj.blank?
21
+ sobj = cobj.subregions.coded(state_iso2)
22
+ if !sobj.blank?
23
+ return sobj.name
24
+ end
25
+ end
26
+ end
27
+ return ""
28
+ end
29
+
30
+ def self.to_s(u)
31
+ str = ""
32
+ str = (u.addressline.blank? ? "" : u.addressline + ", ")
33
+ str = str + (u.city.blank? ? "" : u.city + ", ")
34
+ str = str + (u.zipcode.blank? ? "" : u.zipcode + ", ")
35
+ c = Pyk::Address.country_to_s(u.country_iso2)
36
+ s = Pyk::Address.state_to_s(u.country_iso2, u.subregion_iso2)
37
+ str = str + (s.blank? ? "" : s + ", ")
38
+ str = str + (c.blank? ? "" : c)
39
+ return str
40
+ end
41
+
42
+ def self.gist(u)
43
+ str = ""
44
+ str = (u.city.blank? ? "" : u.city + ", ")
45
+ c = Pyk::Address.country_to_s(u.country_iso2)
46
+ s = Pyk::Address.state_to_s(u.country_iso2, u.subregion_iso2)
47
+ str = str + (s.blank? ? "" : s + ", ")
48
+ str = str + (c.blank? ? "" : c)
49
+ return str
50
+ end
51
+
52
+ def self.gist_no_city(u)
53
+ str = ""
54
+ c = Pyk::Address.country_to_s(u.country_iso2)
55
+ s = Pyk::Address.state_to_s(u.country_iso2, u.subregion_iso2)
56
+ str = str + (s.blank? ? "" : s + ", ")
57
+ str = str + (c.blank? ? "" : c)
58
+ return str
59
+ end
60
+
61
+ #Google Maps Static API
62
+
63
+ def self.map(u, h=300, w=95)
64
+ str = ""
65
+ str = (u.city.blank? ? "" : u.city + "++")
66
+ c = Pyk::Address.country_to_s(u.country_iso2)
67
+ str = str + (c.blank? ? "" : c)
68
+ 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}"
69
+ end
70
+
71
+ end
@@ -0,0 +1,15 @@
1
+ module Pyk::AddressHelpers
2
+
3
+ def location_summary(u)
4
+ return Pyk::Address.to_s(u)
5
+ end
6
+
7
+ def location_summary_short(u)
8
+ return Pyk::Address.gist(u)
9
+ end
10
+
11
+ def location_map(u)
12
+ return Pyk::Address.map(u, 300, 95)
13
+ end
14
+
15
+ end
@@ -0,0 +1,54 @@
1
+ class Pyk::Api
2
+
3
+ require 'open-uri'
4
+ require "net/https"
5
+
6
+ #==========================================================================================
7
+
8
+ #Pyk::Api.basic_auth(url, user_agent, username, password)
9
+ def self.basic_auth(url, user_agent, username, password)
10
+ Pyk::Api.get(url, user_agent, "basic", username, password)
11
+ end
12
+
13
+ #Pyk::Api.no_auth(url, user_agent)
14
+ def self.no_auth(url, user_agent)
15
+ Pyk::Api.get(url, user_agent, nil, nil, nil)
16
+ end
17
+
18
+ #==========================================================================================
19
+
20
+ #Pyk::Api.json(nestful_response)
21
+ def self.json(nestful_response)
22
+ begin
23
+ if !nestful_response.blank?
24
+ if !nestful_response.body.blank?
25
+ return JSON.parse(nestful_response.body)
26
+ end
27
+ end
28
+ return nil
29
+ rescue
30
+ return nil
31
+ end
32
+ end
33
+
34
+ #==========================================================================================
35
+
36
+ private
37
+
38
+ def self.get(url, user_agent, auth_type=nil, username=nil, password=nil)
39
+ uri = URI.parse(url)
40
+ http = Net::HTTP.new(uri.host, uri.port)
41
+ if !url.index("https://").blank?
42
+ http.use_ssl = true
43
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
44
+ end
45
+ request = Net::HTTP::Get.new(uri.request_uri, {'User-Agent' => user_agent})
46
+ if auth_type.present?
47
+ if auth_type == "basic"
48
+ request.basic_auth username, password
49
+ end
50
+ end
51
+ http.request(request)
52
+ end
53
+
54
+ end
@@ -0,0 +1,15 @@
1
+ module Pyk::AppHelpers
2
+
3
+ def title(page_title)
4
+ content_for(:title) { page_title }
5
+ end
6
+
7
+ def d
8
+ "<span style='font-size:13px'><i class='icon-trash'></i></span>".html_safe
9
+ end
10
+
11
+ def r
12
+ "<i class='icon-repeat'></i>".html_safe
13
+ end
14
+
15
+ end
@@ -0,0 +1,18 @@
1
+ class Pyk::Date
2
+
3
+ #Pyk::Date.start_of_financial_year(d)
4
+ def self.start_of_financial_year(d)
5
+ Date.new((d.to_i - 1), 4, 1).to_time
6
+ end
7
+
8
+ #Pyk::Date.end_of_financial_year(d)
9
+ def self.end_of_financial_year(d)
10
+ Date.new(d.to_i, 3, 31).to_time + 86340
11
+ end
12
+
13
+ #Pyk::Date.end_of_month(month, year)
14
+ def self.end_of_month(month, year)
15
+ Date.new(year, month, -1).to_time + 86340
16
+ end
17
+
18
+ end
@@ -0,0 +1,31 @@
1
+ module Pyk::DateHelpers
2
+
3
+ def smart_date(i, mode="date")
4
+ if i.blank?
5
+ return ""
6
+ elsif (i.class.to_s == "Time" or i.class.to_s == "ActiveSupport::TimeWithZone") and mode == "time"
7
+ return i.year == Time.now.year ? i.strftime("%d-%b %H:%M") : i.strftime("%d-%b-%Y %H:%M")
8
+ else
9
+ return i.year == Time.now.year ? i.strftime("%d-%b") : i.strftime("%d-%b-%Y")
10
+ end
11
+ end
12
+
13
+ def smart_due_date(i)
14
+ if i == nil
15
+ return ""
16
+ elsif i.class.to_s == "Time" or i.class.to_s == "ActiveSupport::TimeWithZone"
17
+ i = i.to_date
18
+ end
19
+ if Date.today == i
20
+ return "<span style=\"background-color:#F7FAB9;padding:0px 2px 0px 2px;\">Today</span>"
21
+ elsif i - Date.today == 1
22
+ return "<span style=\"background-color:#F7FAB9;padding:0px 2px 0px 2px;\">Tomorrow</span>"
23
+ elsif Date.today - i > 0.9
24
+ return "<span style=\"background-color:#FFC7C7;padding:0px 2px 0px 2px;\">" + smart_date(i) + "</span>"
25
+ elsif Date.today - i < 1
26
+ return "<span style=\"background-color:#D2FFCC;padding:0px 2px 0px 2px;\">" + smart_date(i) + "</span>"
27
+ end
28
+ return smart_date(i, "date")
29
+ end
30
+
31
+ end
@@ -0,0 +1,31 @@
1
+ class Pyk::DateTime
2
+
3
+ #Pyk::Date.get_start_date_from_tag(tag, default_year=nil, default_month=nil)
4
+ def self.get_start_date_from_tag(tag, default_year=nil, default_month=nil)
5
+ if tag == "this_month"
6
+ return Date.new(Time.now.strftime("%Y").to_i, Time.now.strftime("%m").to_i, 1).to_time
7
+ elsif tag == "last_30"
8
+ return (Date.today - 30).to_time
9
+ elsif tag == "last_month"
10
+ lm = (Time.now - 1.month)
11
+ sdt = Date.new(lm.strftime("%Y").to_i, lm.strftime("%m").to_i, 1)
12
+ return Date.new(lm.strftime("%Y").to_i, lm.strftime("%m").to_i, 1).to_time
13
+ elsif tag == "last_7"
14
+ return (Date.today - 7).to_time
15
+ else
16
+ return Date.new(default_year, default_month, 1).to_time
17
+ end
18
+ end
19
+
20
+ #Pyk::Date.get_end_date_from_tag(tag)
21
+ def self.get_end_date_from_tag(tag)
22
+ if tag == "last_month"
23
+ lm = (Time.now - 1.month)
24
+ sdt = Date.new(lm.strftime("%Y").to_i, lm.strftime("%m").to_i, 1)
25
+ ed = (sdt + 1.month - 1.day).to_time
26
+ else #if tag == "this_month" or tag == "last_30" or tag == "last_7"
27
+ return Time.now
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,45 @@
1
+ module Pyk::DeviseHelpers
2
+
3
+ def resource_name
4
+ :user
5
+ end
6
+
7
+ def resource
8
+ @resource ||= User.new
9
+ end
10
+
11
+ def devise_mapping
12
+ @devise_mapping ||= Devise.mappings[:user]
13
+ end
14
+
15
+ #DEVISE end
16
+
17
+ def devise_error_messages!
18
+ flash_alerts = []
19
+ error_key = 'errors.messages.not_saved'
20
+
21
+ if !flash.empty?
22
+ flash_alerts.push(flash[:error]) if flash[:error]
23
+ flash_alerts.push(flash[:alert]) if flash[:alert]
24
+ flash_alerts.push(flash[:notice]) if flash[:notice]
25
+ error_key = 'devise.failure.invalid'
26
+ end
27
+
28
+ return "" if resource.errors.empty? && flash_alerts.empty?
29
+ errors = resource.errors.empty? ? flash_alerts : resource.errors.full_messages
30
+
31
+ messages = errors.map { |msg| content_tag(:li, msg) }.join
32
+ sentence = I18n.t(error_key, :count => errors.count,
33
+ :resource => resource.class.model_name.human.downcase)
34
+
35
+ html = <<-HTML
36
+ <div id="error_explanation">
37
+ <h2>#{sentence}</h2>
38
+ <ul>#{messages}</ul>
39
+ </div>
40
+ HTML
41
+
42
+ html.html_safe
43
+ end
44
+
45
+ end
@@ -0,0 +1,44 @@
1
+ class Pyk::Dj
2
+
3
+ #Pyk::Dj.bug
4
+ def self.bug
5
+ DelayedJob.where("last_error is not null")
6
+ end
7
+
8
+ #Pyk::Dj.ok
9
+ def self.ok
10
+ DelayedJob.where("last_error is null")
11
+ end
12
+
13
+ #Pyk::Dj.active
14
+ def self.active
15
+ DelayedJob.where("locked_at is not null")
16
+ end
17
+
18
+ #Pyk::Dj.bug_count
19
+ def self.bug_count
20
+ DelayedJob.where("last_error is not null").count
21
+ end
22
+
23
+ #Pyk::Dj.ok_count
24
+ def self.ok_count
25
+ DelayedJob.where("last_error is null").count
26
+ end
27
+
28
+ #Pyk::Dj.active_count
29
+ def self.active_count
30
+ DelayedJob.where("locked_at is not null").count
31
+ end
32
+
33
+ #Pyk::Dj.status(d)
34
+ def self.status(d)
35
+ if !d.last_error.blank?
36
+ return "<span class='red'>Error</span>".html_safe
37
+ elsif d.last_error.blank? and d.locked_at.blank?
38
+ return "<span style='color: orange;'>In Queue</span>".html_safe
39
+ elsif d.last_error.blank? and !d.locked_at.blank?
40
+ return "<span class='green'>Running</span>".html_safe
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,3 @@
1
+ class Pyk::Float
2
+
3
+ end
@@ -0,0 +1,15 @@
1
+ class Pyk::Gravatar
2
+
3
+ #Pyk::Gravatar.dp(email, size)
4
+ def self.dp(email, size=20)
5
+ identifier = Digest::MD5.hexdigest((email.blank? ? "" : email).downcase)
6
+ "http://gravatar.com/avatar/#{identifier}.png?s=#{size}"
7
+ end
8
+
9
+ #Pyk::Gravatar.profile(email)
10
+ def self.profile(email)
11
+ identifier = Digest::MD5.hexdigest((email.blank? ? "" : email).downcase)
12
+ "http://gravatar.com/#{identifier}"
13
+ end
14
+
15
+ end
@@ -0,0 +1,3 @@
1
+ class Pyk::Number
2
+
3
+ end
@@ -0,0 +1,31 @@
1
+ module Pyk::NumberHelpers
2
+
3
+ def two_decimal_points(ff)
4
+ sprintf("%0.02f", ff)
5
+ end
6
+
7
+ def remove_decimal(str)
8
+ str = str.to_s
9
+ if str.index(".").present?
10
+ str = str[0..(str.index(".") - 1)]
11
+ end
12
+ str
13
+ end
14
+
15
+ def n2h(d)
16
+ begin
17
+ return number_to_human(d, significant: false, precision: 1)
18
+ rescue
19
+ return d
20
+ end
21
+ end
22
+
23
+ def color_amount(d)
24
+ if d < 0
25
+ "<span class='red'>(#{number_to_currency(d, unit: '')})</span>".html_safe
26
+ else
27
+ number_to_currency(d, unit: '')
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,12 @@
1
+ class Pyk::Regex
2
+
3
+ #Pyk::Regex::EMAIL
4
+ EMAIL = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
5
+
6
+ #Pyk::Regex::PASSWORD
7
+ PASSWORD = /^(?=.*\d)(?=.*([a-z]|[A-Z]))([\x20-\x7E]){8,}$/
8
+
9
+ #Pyk::Regex::URL
10
+ URL = URI::regexp(%w(http https))
11
+
12
+ end
@@ -0,0 +1,42 @@
1
+ class Pyk::Spreadsheet
2
+
3
+ require 'roo'
4
+
5
+ #MICROSOFT EXCEL STORES DATES AS THE NUMBER OF DAYS FROM 1900. HENCE CONVERSION IS REQUIRED
6
+
7
+ #Pyk::Spreadsheet.process_date_from_xls(d)
8
+ def self.process_date_from_xls(d)
9
+ return nil if d.nil?
10
+ d = d.to_i
11
+ return (Date.new( 1899,12,30) + d)
12
+ end
13
+
14
+ #Pyk::Spreadsheet.is_excel?(data_file_name)
15
+ def self.is_excel?(data_file_name)
16
+ return (!data_file_name.index(".xls").nil? or !data_file_name.index(".ods").nil? or !data_file_name.index(".csv").nil?) ? true : false
17
+ end
18
+
19
+ #Pyk::Spreadsheet.open(url, name, domain)
20
+ def self.open(url, name, domain)
21
+ begin
22
+ url_s = Rails.env.production? ? url.to_s.gsub(domain, "") : (BASE_URL + url.to_s)
23
+ case File.extname(name)
24
+ when ".csv" then s = Csv.new(url_s, nil, :ignore)
25
+ when ".xls" then s = Excel.new(url_s, nil, :ignore)
26
+ when ".xlsx" then s = Excelx.new(url_s, nil, :ignore)
27
+ when ".ods" then s = Openoffice.new(url_s, nil, :ignore)
28
+ else raise "Unknown file type: #{name}"
29
+ end
30
+ s.default_sheet = s.sheets.first
31
+ return s
32
+ rescue
33
+ return "1"
34
+ end
35
+ end
36
+
37
+ #Pyk::Spreadsheet.to_process
38
+ def self.to_process
39
+ ExcelService.where(:pending_process => true)
40
+ end
41
+
42
+ end
@@ -0,0 +1,3 @@
1
+ class Pyk::String
2
+
3
+ end
@@ -0,0 +1,12 @@
1
+ class Pyk::Url
2
+
3
+ # Standardize how web URLs are presented
4
+ # Pyk::Url.clean(link)
5
+ def self.clean(link)
6
+ link = link.gsub("http://", "")
7
+ link = link.gsub("https://", "")
8
+ link = link.gsub("www.", "")
9
+ return "http://#{link}"
10
+ end
11
+
12
+ end
@@ -0,0 +1,8 @@
1
+ class Pyk::User
2
+
3
+ #Pyk::User.is_admin?(current_user.email)
4
+ def self.is_admin?(email)
5
+ (email == "rp@pykih.com" or email == "gs@pykih.com") ? true : false
6
+ end
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pyk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pykih Software LLP
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nestful
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.3
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: carmen
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.13
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.13
55
+ - !ruby/object:Gem::Dependency
56
+ name: roo
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.10.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.10.1
69
+ description:
70
+ email: rp@pykih.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - lib/pyk/address.rb
76
+ - lib/pyk/api.rb
77
+ - lib/pyk/date.rb
78
+ - lib/pyk/date_time.rb
79
+ - lib/pyk/dj.rb
80
+ - lib/pyk/float.rb
81
+ - lib/pyk/gravatar.rb
82
+ - lib/pyk/number.rb
83
+ - lib/pyk/regex.rb
84
+ - lib/pyk/spreadsheet.rb
85
+ - lib/pyk/string.rb
86
+ - lib/pyk/url.rb
87
+ - lib/pyk/user.rb
88
+ - lib/pyk/address_helpers.rb
89
+ - lib/pyk/app_helpers.rb
90
+ - lib/pyk/date_helpers.rb
91
+ - lib/pyk/devise_helpers.rb
92
+ - lib/pyk/number_helpers.rb
93
+ homepage: https://github.com/pykih/pyk
94
+ licenses: []
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 1.3.6
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.0.3
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Standard library of commonly reused functions across all Pykih Projects.
116
+ test_files: []