englify 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/COPYING +13 -0
  2. data/README.md +4 -0
  3. data/Rakefile +10 -0
  4. data/lib/englify.rb +51 -0
  5. metadata +70 -0
data/COPYING ADDED
@@ -0,0 +1,13 @@
1
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
+ Version 2, December 2004
3
+
4
+ Copyright (C) 2012 James Pearson
5
+
6
+ Everyone is permitted to copy and distribute verbatim or modified
7
+ copies of this license document, and changing it is allowed as long
8
+ as the name is changed.
9
+
10
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12
+
13
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ Sometimes people give you artist names in moonrunes. I can't read 'em, so
2
+ englify attempts to use the MusicBrainz database to get a romanized version.
3
+ If it can't, you'll just get back what you put in.
4
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'mg'
2
+ MG.new('englify.gemspec')
3
+
4
+ require 'fileutils'
5
+ require 'rake/testtask'
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.libs << 'test'
9
+ end
10
+
data/lib/englify.rb ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ # May you recognize your weaknesses and share your strengths.
4
+ # May you share freely, never taking more than you give.
5
+ # May you find love and love everyone you find.
6
+
7
+ require 'rbrainz'
8
+
9
+ # Trying to match on an artist whose name is in crazy moonrunes causes REXML to
10
+ # complain about mismatched encodings. So, we force UTF-8.
11
+ module MusicBrainz
12
+ module Webservice
13
+ class MBXML
14
+ alias old_initialize initialize
15
+ def initialize(stream, factory=nil)
16
+ stream.set_encoding 'UTF-8'
17
+ old_initialize(stream, factory)
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def englify(name)
24
+ filter = MusicBrainz::Webservice::ArtistFilter.new(
25
+ :name => name,
26
+ :limit => 1
27
+ )
28
+ query = MusicBrainz::Webservice::Query.new
29
+ artists = query.get_artists(filter)
30
+ # Can't find 'em? Just assume they're alright.
31
+ if artists[0].nil?
32
+ return name
33
+ end
34
+ artist = artists[0].entity
35
+
36
+ # This *should* work, but it gives us nothing.
37
+ #return artist.aliases[0]
38
+
39
+ id = artist.id
40
+ artist_includes = MusicBrainz::Webservice::ArtistIncludes.new(
41
+ :aliases => true
42
+ )
43
+ artist = query.get_artist_by_id(id, artist_includes)
44
+ englifiedName = artist.aliases[0].to_s
45
+ if englifiedName == ''
46
+ englifiedName = name
47
+ end
48
+
49
+ return englifiedName
50
+ end
51
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: englify
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - xiongchiamiov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-03-17 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rbrainz
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: Turn moonruned artist names into Romanized alternatives.
28
+ email:
29
+ - xiong.chiamiov@gmail.com
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files:
35
+ - README.md
36
+ files:
37
+ - COPYING
38
+ - Rakefile
39
+ - README.md
40
+ - lib/englify.rb
41
+ has_rdoc: true
42
+ homepage: https://github.com/xiongchiamiov/englify/
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.5.3
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Turn moonruned artist names into Romanized alternatives.
69
+ test_files: []
70
+