beatport 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/beatport.gemspec +9 -8
- data/lib/beatport.rb +1 -3
- data/lib/beatport/catalog/account_type.rb +7 -1
- data/lib/beatport/catalog/artist.rb +8 -5
- data/lib/beatport/catalog/audio_format.rb +5 -0
- data/lib/beatport/catalog/autocomplete.rb +1 -1
- data/lib/beatport/catalog/chart.rb +12 -6
- data/lib/beatport/catalog/country.rb +1 -1
- data/lib/beatport/catalog/feature.rb +1 -1
- data/lib/beatport/catalog/genre.rb +10 -6
- data/lib/beatport/catalog/label.rb +5 -5
- data/lib/beatport/catalog/mixed.rb +1 -1
- data/lib/beatport/catalog/release.rb +10 -5
- data/lib/beatport/catalog/search.rb +1 -1
- data/lib/beatport/catalog/slide.rb +3 -3
- data/lib/beatport/catalog/track.rb +18 -12
- data/lib/beatport/client.rb +9 -3
- data/lib/beatport/collection.rb +1 -1
- data/lib/beatport/support.rb +7 -0
- data/lib/beatport/support/inflector.rb +47 -0
- data/lib/beatport/support/parser.rb +10 -0
- data/lib/beatport/support/query_builder.rb +88 -0
- data/spec/catalog/account_type_spec.rb +29 -8
- data/spec/catalog/artist_spec.rb +41 -18
- data/spec/catalog/audio_format_spec.rb +23 -5
- data/spec/catalog/autocomplete_spec.rb +23 -14
- data/spec/catalog/chart_overview_spec.rb +4 -5
- data/spec/catalog/chart_spec.rb +37 -18
- data/spec/catalog/country_spec.rb +16 -14
- data/spec/catalog/currency_spec.rb +6 -4
- data/spec/catalog/genre_spec.rb +24 -50
- data/spec/catalog/home_spec.rb +7 -8
- data/spec/catalog/item_type_spec.rb +5 -3
- data/spec/catalog/label_spec.rb +20 -19
- data/spec/catalog/mixed_spec.rb +4 -4
- data/spec/catalog/release_spec.rb +26 -24
- data/spec/catalog/source_type_spec.rb +5 -3
- data/spec/catalog/track_spec.rb +31 -30
- data/spec/{inflector_spec.rb → support/inflector_spec.rb} +1 -1
- data/spec/{query_builder_spec.rb → support/query_builder_spec.rb} +13 -19
- metadata +10 -9
- data/lib/beatport/inflector.rb +0 -44
- data/lib/beatport/parser.rb +0 -8
- data/lib/beatport/query_builder.rb +0 -74
data/spec/catalog/home_spec.rb
CHANGED
@@ -3,14 +3,13 @@ require 'spec_helper'
|
|
3
3
|
module Beatport::Catalog
|
4
4
|
describe Home do
|
5
5
|
describe '.get' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
6
|
+
subject { Home.get }
|
7
|
+
|
8
|
+
it { should be_a(Home) }
|
9
|
+
its (:'slideshow.header.length') { should be >= 1 }
|
10
|
+
its (:'slideshow.feature.length') { should be > 1 }
|
11
|
+
its (:'features.length') { should be > 1 }
|
12
|
+
its (:'top_downloads.length') { should be > 1 }
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
@@ -3,9 +3,11 @@ require 'spec_helper'
|
|
3
3
|
module Beatport::Catalog
|
4
4
|
describe ItemType do
|
5
5
|
describe "structure" do
|
6
|
-
|
7
|
-
|
8
|
-
it {
|
6
|
+
subject { ItemType.all.first }
|
7
|
+
|
8
|
+
it { should be_an(ItemType) }
|
9
|
+
its (:id) { should == 1 }
|
10
|
+
its (:name) { should == "track" }
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
data/spec/catalog/label_spec.rb
CHANGED
@@ -4,24 +4,25 @@ module Beatport::Catalog
|
|
4
4
|
describe Label do
|
5
5
|
|
6
6
|
describe 'structure' do
|
7
|
-
|
8
|
-
it { @label.id.should == 1390 }
|
9
|
-
it { @label.type.should == "label" }
|
10
|
-
it { @label.name.should == "Anjunadeep" }
|
11
|
-
it { @label.slug.should == "anjunadeep" }
|
12
|
-
it { @label.source_type.should == ["store", "mobile", "sushi"] }
|
13
|
-
it { @label.last_publish_date.should == Date.new(2011, 12, 07) }
|
14
|
-
it { @label.biography.should == "" }
|
15
|
-
it { @label.genres.length.should be > 1 }
|
16
|
-
it { @label.sub_genres.length.should be > 0 }
|
17
|
-
it { @label.display_level.should == 1 }
|
18
|
-
it { @label.images.small.url.should == "http://geo-media.beatport.com/items/imageCatalog/0/0/0/3000/400/0/3406.jpg"}
|
19
|
-
it { @label.images.medium.url.should == "http://geo-media.beatport.com/items/imageCatalog/0/0/0/1000/100/90/1191.jpg"}
|
20
|
-
it { @label.images.banner.url.should == "http://geo-media.beatport.com/items/imageCatalog/0/300000/40000/5000/100/50/345152.jpg"}
|
7
|
+
subject { Label.find(1390) }
|
21
8
|
|
22
|
-
it {
|
23
|
-
|
24
|
-
|
9
|
+
it { should be_a(Label) }
|
10
|
+
its (:id) { should == 1390 }
|
11
|
+
its (:type) { should == "label" }
|
12
|
+
its (:name) { should == "Anjunadeep" }
|
13
|
+
its (:slug) { should == "anjunadeep" }
|
14
|
+
its (:source_type) { should == ["store", "mobile", "sushi"] }
|
15
|
+
its (:last_publish_date) { should == Date.new(2011, 12, 07) }
|
16
|
+
its (:biography) { should == "" }
|
17
|
+
its (:'genres.length') { should be > 1 }
|
18
|
+
its (:'sub_genres.length') { should be > 0 }
|
19
|
+
its (:display_level) { should == 1 }
|
20
|
+
its (:'images.small.url') { should == "http://geo-media.beatport.com/items/imageCatalog/0/0/0/3000/400/0/3406.jpg"}
|
21
|
+
its (:'images.medium.url') { should == "http://geo-media.beatport.com/items/imageCatalog/0/0/0/1000/100/90/1191.jpg"}
|
22
|
+
its (:'images.banner.url') { should == "http://geo-media.beatport.com/items/imageCatalog/0/300000/40000/5000/100/50/345152.jpg"}
|
23
|
+
# its (:'top_downloads.length') { should be > 1 }
|
24
|
+
# its (:'featured_releases.length') { should be > 1 }
|
25
|
+
# its (:'most_popular_releases.length') { should be > 1 }
|
25
26
|
end
|
26
27
|
|
27
28
|
describe '.find' do
|
@@ -55,7 +56,7 @@ module Beatport::Catalog
|
|
55
56
|
old_id = nil if old_date.to_s != label.last_publish_date.to_s
|
56
57
|
|
57
58
|
# beatport has some bad genre data?
|
58
|
-
# label.genres.map(&:id)
|
59
|
+
# label.genres.map(&:id)) { should include(5)
|
59
60
|
label.id.should be >= old_id if old_id
|
60
61
|
label.last_publish_date.should be >= old_date if old_date
|
61
62
|
|
@@ -68,7 +69,7 @@ module Beatport::Catalog
|
|
68
69
|
labels = Label.all :return_facets => ['genre_name', 'performer_name']
|
69
70
|
|
70
71
|
# no worky
|
71
|
-
# labels.facets['fields']['performer_name'].count
|
72
|
+
# labels.facets['fields']['performer_name'].count) { should be > 1
|
72
73
|
labels.facets['fields']['genre_name'].count.should be > 1
|
73
74
|
end
|
74
75
|
|
data/spec/catalog/mixed_spec.rb
CHANGED
@@ -3,8 +3,8 @@ require 'spec_helper'
|
|
3
3
|
module Beatport::Catalog
|
4
4
|
describe Mixed do
|
5
5
|
describe '.all' do
|
6
|
-
|
7
|
-
|
6
|
+
subject do
|
7
|
+
Mixed.all(
|
8
8
|
:label_ids => [804,1390],
|
9
9
|
:artist_ids => [7181, 10395],
|
10
10
|
:chart_ids => [15722, 29514],
|
@@ -14,11 +14,11 @@ module Beatport::Catalog
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should return two of each type" do
|
17
|
-
|
17
|
+
subject.map(&:type).should == ['label', 'label', 'artist', 'artist', 'chart', 'chart', 'release', 'release', 'track', 'track']
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should return the right ids" do
|
21
|
-
|
21
|
+
subject.map(&:id).should == [804, 1390, 7181, 10395, 15722, 29514, 164808, 385763, 1746687, 1873426]
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
@@ -4,30 +4,32 @@ module Beatport::Catalog
|
|
4
4
|
describe Release do
|
5
5
|
|
6
6
|
describe 'structure' do
|
7
|
-
|
8
|
-
|
9
|
-
it {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
7
|
+
subject { Release.find(164808) }
|
8
|
+
|
9
|
+
it { should be_a(Release) }
|
10
|
+
its (:id) { should == 164808 }
|
11
|
+
its (:type) { should == 'release' }
|
12
|
+
its (:name) { should == "Anjunabeats Volume 6 (Unmixed - DJ Ready)" }
|
13
|
+
its (:slug) { should == 'anjunabeats-volume-6-unmixed-dj-ready'}
|
14
|
+
its (:release_date) { should == Date.new(2009, 04, 06) }
|
15
|
+
its (:publish_date) { should == Date.new(2009, 04, 06) }
|
16
|
+
its (:exclusive) { should == false }
|
17
|
+
its (:category) { should == 'Album' }
|
18
|
+
its (:current_status) { should == "General Content"}
|
19
|
+
its (:catalog_number) { should == "ANJCDCO011D"}
|
20
|
+
its (:purchasable) { should == true }
|
21
|
+
its (:'price.to_s') { should == "15.99" }
|
22
|
+
its (:'tracks_price.to_s') { should == "43.21" }
|
23
|
+
its (:'audio_format_fee.wav.to_s') { should == '29.00'}
|
24
|
+
its (:'audio_format_fee.aiff.to_s') { should == '29.00'}
|
25
|
+
its (:'label.id') { should == 804 }
|
26
|
+
specify { subject.artists.map(&:name).should include("Paul Keeley") }
|
27
|
+
specify { subject.genres.map(&:name).should == ["Trance", "Progressive House"] }
|
28
|
+
its (:'images.small.url') { should == "http://geo-media.beatport.com/items/imageCatalog/0/300000/90000/2000/600/90/392699.jpg" }
|
29
|
+
its (:'images.medium.url') { should == "http://geo-media.beatport.com/items/imageCatalog/0/300000/90000/2000/700/0/392700.jpg" }
|
30
|
+
its (:'images.large.url') { should == "http://geo-media.beatport.com/items/imageCatalog/0/300000/90000/2000/700/0/392701.jpg" }
|
31
|
+
its (:'discount.to_s') { should == "27.22" }
|
32
|
+
# its (:'recommendations.releases.length') { should > 1 }
|
31
33
|
end
|
32
34
|
|
33
35
|
describe '.find' do
|
@@ -3,9 +3,11 @@ require 'spec_helper'
|
|
3
3
|
module Beatport::Catalog
|
4
4
|
describe SourceType do
|
5
5
|
describe "structure" do
|
6
|
-
|
7
|
-
|
8
|
-
it {
|
6
|
+
subject { SourceType.all.first }
|
7
|
+
|
8
|
+
it { should be_a(SourceType) }
|
9
|
+
its (:id) { should == 1 }
|
10
|
+
its (:name) { should == "store" }
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
data/spec/catalog/track_spec.rb
CHANGED
@@ -10,38 +10,39 @@ module Beatport::Catalog
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe 'structure' do
|
13
|
-
|
13
|
+
subject { Track.find(1217790) }
|
14
14
|
|
15
|
-
it {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
15
|
+
it { should be_a(Track) }
|
16
|
+
its (:id) { should == 1217790 }
|
17
|
+
its (:type) { should == 'track' }
|
18
|
+
its (:name) { should == "Tonight (IMS Anthem 2009)" }
|
19
|
+
its (:mix_name) { should == "Above & Beyond Remix" }
|
20
|
+
its (:slug) { should == "tonight-ims-anthem-2009-above-and-beyond-remix" }
|
21
|
+
its (:title) { should == "Tonight (IMS Anthem 2009) (Above & Beyond Remix)"}
|
22
|
+
its (:release_date) { should == Date.new(2010,05,17) }
|
23
|
+
its (:publish_date) { should == Date.new(2010,05,17) }
|
24
|
+
its (:sample_url) { should == 'http://geo-samples.beatport.com/items/volumes/volume7/items/1000000/200000/10000/7000/700/90/1217790.LOFI.mp3' }
|
25
|
+
its (:rtmp_stream_url) { should == 'rtmp://geo-rtmp-samples.beatport.com/beatport/_definst_/mp3:lofi_samples/items/volumes/volume7/items/1000000/200000/10000/7000/700/90/1217790.LOFI'}
|
26
|
+
its (:exclusive) { should be_false }
|
27
|
+
its (:'price.to_s') { should == "1.49" }
|
28
|
+
its (:'audio_format_fee.wav.to_s') { should == "1.00" }
|
29
|
+
its (:'audio_format_fee.aiff.to_s') { should == "1.00" }
|
29
30
|
# for some reason this doesn't always return the same result
|
30
|
-
# it { @track.current_status
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
31
|
+
# it { @track.current_status) { should == nil "General Content" }
|
32
|
+
its (:length) { should == "07:53" }
|
33
|
+
its (:bpm) { should == 128 }
|
34
|
+
its (:'key.standard.letter') { should == "D" }
|
35
|
+
its (:sale_type) { should == "purchase" }
|
36
|
+
specify { subject.artists.map(&:name).should == ["Above & Beyond", "Dirty Vegas"] }
|
37
|
+
specify { subject.genres.map(&:name).should == ["Trance"] }
|
38
|
+
specify { subject.sub_genres.map(&:name).should == ['Progressive'] }
|
39
|
+
its (:charts) { should == [] }
|
40
|
+
its (:'release.id') { should == 245137 }
|
41
|
+
its (:'label.id') { should == 495}
|
42
|
+
its (:'images.small.url') { should == 'http://geo-media.beatport.com/items/imageCatalog/0/600000/70000/4000/700/50/674759.jpg' }
|
43
|
+
its (:'images.medium.url') { should == 'http://geo-media.beatport.com/items/imageCatalog/0/600000/70000/4000/700/60/674760.jpg' }
|
44
|
+
its (:'images.large.url') { should == 'http://geo-media.beatport.com/items/imageCatalog/0/600000/70000/4000/700/60/674761.jpg' }
|
45
|
+
its (:'images.waveform.url') { should == 'http://geo-media.beatport.com/items/imageCatalog/1000000/200000/60000/8000/200/20/1268229.png' }
|
45
46
|
end
|
46
47
|
|
47
48
|
describe '.find' do
|
@@ -1,23 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module Beatport
|
3
|
+
module Beatport::Support
|
4
4
|
describe QueryBuilder do
|
5
5
|
describe '#process_sort_by' do
|
6
|
-
it "
|
6
|
+
it "handles strings" do
|
7
7
|
input = 'publish_date desc, chart_id desc'
|
8
8
|
output = 'publishDate desc,chartId desc'
|
9
9
|
|
10
10
|
QueryBuilder.new.process_sort_by(input).should == output
|
11
11
|
end
|
12
12
|
|
13
|
-
it "
|
13
|
+
it "handles arrays" do
|
14
14
|
input = ['publish_date desc', 'chart_id desc']
|
15
15
|
output = 'publishDate desc,chartId desc'
|
16
16
|
|
17
17
|
QueryBuilder.new.process_sort_by(input).should == output
|
18
18
|
end
|
19
19
|
|
20
|
-
it "
|
20
|
+
it "handles hashes" do
|
21
21
|
input = {'publish_date' => 'desc', 'chart_id' => 'desc'}
|
22
22
|
output = 'publishDate desc,chartId desc'
|
23
23
|
|
@@ -26,21 +26,21 @@ module Beatport
|
|
26
26
|
end
|
27
27
|
|
28
28
|
describe '#process_facets' do
|
29
|
-
it "
|
29
|
+
it "handles strings" do
|
30
30
|
input = "genre_name:Trance, genre_name:Progressive House"
|
31
31
|
output = "genreName:Trance,genreName:Progressive House"
|
32
32
|
|
33
33
|
QueryBuilder.new.process_facets(input).should == output
|
34
34
|
end
|
35
35
|
|
36
|
-
it "
|
36
|
+
it "handles arrays" do
|
37
37
|
input = ["genre_name:Trance", "genre_name:Progressive House"]
|
38
38
|
output = "genreName:Trance,genreName:Progressive House"
|
39
39
|
|
40
40
|
QueryBuilder.new.process_facets(input).should == output
|
41
41
|
end
|
42
42
|
|
43
|
-
it "
|
43
|
+
it "handles hashes with string values" do
|
44
44
|
input = {"genre_name" => "Trance"}
|
45
45
|
output = "genreName:Trance"
|
46
46
|
|
@@ -48,7 +48,7 @@ module Beatport
|
|
48
48
|
end
|
49
49
|
|
50
50
|
|
51
|
-
it "
|
51
|
+
it "handles hashes with array values" do
|
52
52
|
input = {"genre_name" => ["Trance", "Progressive House"]}
|
53
53
|
output = "genreName:Trance,genreName:Progressive House"
|
54
54
|
|
@@ -57,7 +57,7 @@ module Beatport
|
|
57
57
|
end
|
58
58
|
|
59
59
|
describe '#process_return_facets' do
|
60
|
-
it "
|
60
|
+
it "handles strings" do
|
61
61
|
input = "genre_name, performer_name"
|
62
62
|
output = "genreName,performerName"
|
63
63
|
|
@@ -66,31 +66,25 @@ module Beatport
|
|
66
66
|
end
|
67
67
|
|
68
68
|
describe ".process" do
|
69
|
-
it "
|
69
|
+
it "handles sort by" do
|
70
70
|
h = {:sort_by => ['publishDate asc', 'chartId asc']}
|
71
71
|
|
72
72
|
QueryBuilder.process(h).should == {'sortBy'=>"publishDate asc,chartId asc"}
|
73
73
|
end
|
74
74
|
|
75
|
-
it "
|
75
|
+
it "handles sort by with hash syntax" do
|
76
76
|
h = {:sort_by => {'publish_date'=>'asc', 'chart_id'=>'asc'}}
|
77
77
|
|
78
78
|
QueryBuilder.process(h).should == {'sortBy'=>"publishDate asc,chartId asc"}
|
79
79
|
end
|
80
80
|
|
81
|
-
it "
|
81
|
+
it "handles return facets" do
|
82
82
|
h = {:return_facets => ['genre_name', 'performer_name']}
|
83
83
|
|
84
84
|
QueryBuilder.process(h).should == {'returnFacets'=>"genreName,performerName"}
|
85
85
|
end
|
86
86
|
|
87
|
-
it "
|
88
|
-
h = {:return_facets => ['genre_name', 'performer_name']}
|
89
|
-
|
90
|
-
QueryBuilder.process(h).should == {'returnFacets'=>"genreName,performerName"}
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should handle facets" do
|
87
|
+
it "handles facets" do
|
94
88
|
h = {:facets => {:genre_name => ['Trance', 'Progessive House']}}
|
95
89
|
|
96
90
|
QueryBuilder.process(h).should == {'facets'=>"genreName:Trance,genreName:Progessive House"}
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beatport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mateo Murphy
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-12-
|
18
|
+
date: 2011-12-21 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -185,11 +185,12 @@ files:
|
|
185
185
|
- lib/beatport/catalog/track.rb
|
186
186
|
- lib/beatport/client.rb
|
187
187
|
- lib/beatport/collection.rb
|
188
|
-
- lib/beatport/inflector.rb
|
189
188
|
- lib/beatport/item.rb
|
190
|
-
- lib/beatport/parser.rb
|
191
189
|
- lib/beatport/price.rb
|
192
|
-
- lib/beatport/
|
190
|
+
- lib/beatport/support.rb
|
191
|
+
- lib/beatport/support/inflector.rb
|
192
|
+
- lib/beatport/support/parser.rb
|
193
|
+
- lib/beatport/support/query_builder.rb
|
193
194
|
- spec/catalog/account_type_spec.rb
|
194
195
|
- spec/catalog/artist_spec.rb
|
195
196
|
- spec/catalog/audio_format_spec.rb
|
@@ -209,10 +210,10 @@ files:
|
|
209
210
|
- spec/catalog/source_type_spec.rb
|
210
211
|
- spec/catalog/track_spec.rb
|
211
212
|
- spec/collection_spec.rb
|
212
|
-
- spec/inflector_spec.rb
|
213
213
|
- spec/item_spec.rb
|
214
|
-
- spec/query_builder_spec.rb
|
215
214
|
- spec/spec_helper.rb
|
215
|
+
- spec/support/inflector_spec.rb
|
216
|
+
- spec/support/query_builder_spec.rb
|
216
217
|
has_rdoc: true
|
217
218
|
homepage: http://github.com/mateomurphy/beatport
|
218
219
|
licenses:
|
data/lib/beatport/inflector.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
module Beatport
|
2
|
-
module Inflector
|
3
|
-
def self.constantize(camel_cased_word)
|
4
|
-
names = camel_cased_word.split('::')
|
5
|
-
names.shift if names.empty? || names.first.empty?
|
6
|
-
|
7
|
-
constant = Object
|
8
|
-
names.each do |name|
|
9
|
-
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
10
|
-
end
|
11
|
-
constant
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
|
15
|
-
if first_letter_in_uppercase
|
16
|
-
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
17
|
-
else
|
18
|
-
lower_case_and_underscored_word.to_s[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..-1]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.underscore(camel_cased_word)
|
23
|
-
word = camel_cased_word.to_s.dup
|
24
|
-
word.gsub!(/::/, '/')
|
25
|
-
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
26
|
-
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
27
|
-
word.tr!("-", "_")
|
28
|
-
word.downcase!
|
29
|
-
word
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.process_keys(obj, &block)
|
33
|
-
case obj
|
34
|
-
when Hash
|
35
|
-
Hash[obj.map {|k, v| [yield(k), process_keys(v, &block)]}]
|
36
|
-
when Array
|
37
|
-
obj.map {|o| process_keys(o, &block)}
|
38
|
-
else
|
39
|
-
obj
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
end
|