php4r 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/php4r.rb +23 -32
- data/php4r.gemspec +66 -0
- data/spec/php4r_spec.rb +8 -0
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/lib/php4r.rb
CHANGED
@@ -143,10 +143,6 @@ module Php4r
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
-
def gtext(string)
|
147
|
-
return GetText._(string)
|
148
|
-
end
|
149
|
-
|
150
146
|
def gettext(string)
|
151
147
|
return GetText._(string)
|
152
148
|
end
|
@@ -195,7 +191,7 @@ module Php4r
|
|
195
191
|
end
|
196
192
|
|
197
193
|
def http_build_query(obj)
|
198
|
-
return
|
194
|
+
return Php4r.http_build_query_rec("", obj)
|
199
195
|
end
|
200
196
|
|
201
197
|
def http_build_query_rec(orig_key, obj, first = true)
|
@@ -210,7 +206,7 @@ module Php4r
|
|
210
206
|
val = "#<Model::#{val.table}::#{val.id}>" if val.respond_to?("is_knj?")
|
211
207
|
|
212
208
|
if val.is_a?(Hash) or val.is_a?(Array)
|
213
|
-
url <<
|
209
|
+
url << Php4r.http_build_query_rec(orig_key_str, val, false)
|
214
210
|
else
|
215
211
|
url << "&" if !first or !first_ele
|
216
212
|
url << "#{Php4r.urlencode(orig_key_str)}=#{Php4r.urlencode(val)}"
|
@@ -230,7 +226,7 @@ module Php4r
|
|
230
226
|
val = "#<Model::#{val.table}::#{val.id}>" if val.respond_to?("is_knj?")
|
231
227
|
|
232
228
|
if val.is_a?(Hash) or val.is_a?(Array)
|
233
|
-
url <<
|
229
|
+
url << Php4r.http_build_query_rec(orig_key_str, val, false)
|
234
230
|
else
|
235
231
|
url << "&" if !first or !first_ele
|
236
232
|
url << "#{Php4r.urlencode(orig_key_str)}=#{Php4r.urlencode(val)}"
|
@@ -393,10 +389,12 @@ module Php4r
|
|
393
389
|
end
|
394
390
|
|
395
391
|
def strtotime(date_string, cur = nil)
|
392
|
+
require "datet"
|
393
|
+
|
396
394
|
if !cur
|
397
|
-
cur =
|
395
|
+
cur = Datet.new
|
398
396
|
else
|
399
|
-
cur = Time.at(cur)
|
397
|
+
cur = Datet.new(Time.at(cur))
|
400
398
|
end
|
401
399
|
|
402
400
|
date_string = date_string.to_s.downcase
|
@@ -413,28 +411,22 @@ module Php4r
|
|
413
411
|
timestr = match[3]
|
414
412
|
number = match[2].to_i
|
415
413
|
mathval = match[1]
|
416
|
-
|
414
|
+
number = -number if mathval == "-"
|
417
415
|
|
418
416
|
if timestr == "years" or timestr == "year"
|
419
|
-
|
417
|
+
cur.add_years(number)
|
420
418
|
elsif timestr == "months" or timestr == "month"
|
421
|
-
|
419
|
+
cur.add_months(number)
|
422
420
|
elsif timestr == "weeks" or timestr == "week"
|
423
|
-
|
421
|
+
cur.add_days(number * 7)
|
424
422
|
elsif timestr == "days" or timestr == "day"
|
425
|
-
|
423
|
+
cur.add_days(number)
|
426
424
|
elsif timestr == "hours" or timestr == "hour"
|
427
|
-
|
425
|
+
cur.add_hours(number)
|
428
426
|
elsif timestr == "minutes" or timestr == "minute" or timestr == "min" or timestr == "mints"
|
429
|
-
|
427
|
+
cur.add_minutes(timestr)
|
430
428
|
elsif timestr == "seconds" or timestr == "second" or timestr == "sec" or timestr == "secs"
|
431
|
-
|
432
|
-
end
|
433
|
-
|
434
|
-
if mathval == "+"
|
435
|
-
cur += add
|
436
|
-
elsif mathval == "-"
|
437
|
-
cur -= add
|
429
|
+
cur.add_seconds(number)
|
438
430
|
end
|
439
431
|
end
|
440
432
|
|
@@ -662,17 +654,16 @@ module Php4r
|
|
662
654
|
month = cur_time.month if month == nil
|
663
655
|
year = cur_time.year if year == nil
|
664
656
|
|
665
|
-
|
666
|
-
return new_time.to_i
|
657
|
+
return Time.new(year, month, date, hour, min, sec).to_i
|
667
658
|
end
|
668
659
|
|
669
660
|
def date(date_format, date_input = nil)
|
670
661
|
if date_input == nil
|
671
662
|
date_object = Time.now
|
663
|
+
elsif date_input.respond_to?(:to_time)
|
664
|
+
date_object = date_input.to_time
|
672
665
|
elsif Php4r.is_numeric(date_input)
|
673
666
|
date_object = Time.at(date_input.to_i)
|
674
|
-
elsif date_input.is_a?(Datet)
|
675
|
-
date_object = date_input.time
|
676
667
|
elsif date_input.is_a?(Time)
|
677
668
|
date_object = date_input
|
678
669
|
else
|
@@ -713,7 +704,7 @@ module Php4r
|
|
713
704
|
|
714
705
|
return {
|
715
706
|
"dirname" => dirname,
|
716
|
-
"basename" =>
|
707
|
+
"basename" => Php4r.basename(filepath),
|
717
708
|
"extension" => filepath.split(".").last,
|
718
709
|
"filename" => filepath.split("/").last
|
719
710
|
}
|
@@ -738,7 +729,7 @@ module Php4r
|
|
738
729
|
|
739
730
|
# Should return the peak usage of the running script, but I have found no way to detect this... Instead returns the currently memory usage.
|
740
731
|
def memory_get_peak_usage
|
741
|
-
return
|
732
|
+
return Php4r.memory_get_usage
|
742
733
|
end
|
743
734
|
|
744
735
|
def ip2long(ip)
|
@@ -950,7 +941,7 @@ module Php4r
|
|
950
941
|
|
951
942
|
private
|
952
943
|
|
953
|
-
def
|
944
|
+
def Php4r.parse_str_name(seton, varname, value)
|
954
945
|
if value.respond_to?(:filename) and value.filename
|
955
946
|
realvalue = value
|
956
947
|
else
|
@@ -978,7 +969,7 @@ module Php4r
|
|
978
969
|
end
|
979
970
|
end
|
980
971
|
|
981
|
-
def
|
972
|
+
def Php4r.parse_str_secname(seton, secname)
|
982
973
|
secname_empty = false
|
983
974
|
if secname.length <= 0
|
984
975
|
secname_empty = true
|
@@ -998,7 +989,7 @@ module Php4r
|
|
998
989
|
return [secname, secname_empty]
|
999
990
|
end
|
1000
991
|
|
1001
|
-
def
|
992
|
+
def Php4r.parse_str_name_second(seton, varname, value)
|
1002
993
|
if value.respond_to?(:filename) and value.filename
|
1003
994
|
realvalue = value
|
1004
995
|
else
|
data/php4r.gemspec
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{php4r}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kasper Johansen"]
|
12
|
+
s.date = %q{2012-07-28}
|
13
|
+
s.description = %q{A lib containing various PHP-functions coded in Ruby. You can either use it or use it as a reference, if you are coming from PHP to Ruby or the other way around.}
|
14
|
+
s.email = %q{k@spernj.org}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/php4r.rb",
|
29
|
+
"php4r.gemspec",
|
30
|
+
"spec/php4r_spec.rb",
|
31
|
+
"spec/spec_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/kaspernj/php4r}
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.6.2}
|
37
|
+
s.summary = %q{A lib containing various PHP-functions coded in Ruby.}
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_runtime_dependency(%q<http2>, [">= 0"])
|
44
|
+
s.add_runtime_dependency(%q<datet>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
46
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
47
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
48
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<http2>, [">= 0"])
|
51
|
+
s.add_dependency(%q<datet>, [">= 0"])
|
52
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
53
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
54
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
55
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<http2>, [">= 0"])
|
59
|
+
s.add_dependency(%q<datet>, [">= 0"])
|
60
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
61
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
62
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
63
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
data/spec/php4r_spec.rb
CHANGED
@@ -36,6 +36,14 @@ describe "Php4r" do
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
it "strtotime" do
|
40
|
+
time = Time.new(2010, 1, 1)
|
41
|
+
newtime = Php4r.strtotime("+1 year +1 day +2 months", time.to_i)
|
42
|
+
newtime = Datet.new(Time.at(newtime))
|
43
|
+
|
44
|
+
raise "Expected dbstr to be '2011-03-02 00:00:00' but it wasnt: '#{newtime.dbstr}'." if newtime.dbstr != "2011-03-02 00:00:00"
|
45
|
+
end
|
46
|
+
|
39
47
|
it "substr" do
|
40
48
|
res = Php4r.substr("selcol_15", 7)
|
41
49
|
raise "substr should have returned '15' but didnt: '#{res}'." if res != "15"
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: php4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kasper Johansen
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- Rakefile
|
99
99
|
- VERSION
|
100
100
|
- lib/php4r.rb
|
101
|
+
- php4r.gemspec
|
101
102
|
- spec/php4r_spec.rb
|
102
103
|
- spec/spec_helper.rb
|
103
104
|
has_rdoc: true
|
@@ -114,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
115
|
requirements:
|
115
116
|
- - ">="
|
116
117
|
- !ruby/object:Gem::Version
|
117
|
-
hash:
|
118
|
+
hash: 3717817282737004000
|
118
119
|
segments:
|
119
120
|
- 0
|
120
121
|
version: "0"
|