hiragana_codes 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a4392a4b8d2764fc7c067239b5824b884833d48
4
+ data.tar.gz: 6272da5de290ea9463290f47a28509705b89b72c
5
+ SHA512:
6
+ metadata.gz: f7457c1b95e7c83b5d18479ad0ecfdc48d552629e926e68286705753f67d017b02a591c6015b467e2c6df37fdf0c44aa031bcf621eb33f0ec8354bbfe6cb8ca8
7
+ data.tar.gz: 3bb7baf9dbe3eee3cbfc784e83b7503d16bd63b9e4a7f86b0182ed9cdc89b0dcaa7f2d389e683b3db978c8a8fabe2311d59b211c058b90a6f343ad9201fed3bd
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hiragana_codes.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 sei0o
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,75 @@
1
+ # HiraganaCodes (ひらがなコード)
2
+
3
+ ## 概要
4
+ - 文字は`あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもらりるれろ`(40文字)を、この順で使います。
5
+ - `やゆよわをん`を除外します。
6
+ - `hiragana_codes.rb`の`CHARACTERS`定数を変更すれば、使う文字をカタカナや漢字、絵文字にもできます。
7
+ - 二桁ずつ変換します。
8
+ 1. 地球を緯度4.5度ごと、経度9度ごとに区切ります(文字数によって変化)。
9
+ 2. 上記の文字を割り当てて、緯度経度の順に並べます。
10
+ 3. 繰り返し
11
+
12
+ ## 例
13
+ - 国会議事堂前
14
+ - 35.675796, 139.743786
15
+ - すらうにらえさせりねうぬ
16
+ - ホワイトハウス
17
+ - 38.89769091235223, -77.03655930429916
18
+ - ししそつこのへのたてめふ
19
+ - 新大阪駅
20
+ - 34.7331654, 135.5002144
21
+ - すらしうさけつるけえかけ
22
+
23
+ ## インストール
24
+ ```
25
+ $ gem install hiragana_codes
26
+ ```
27
+
28
+ ```ruby
29
+ gem 'hiragana_codes'
30
+ ```
31
+
32
+ ## 使い方
33
+ - Encoding
34
+
35
+ ```ruby
36
+ require 'hiragana_codes'
37
+ HiraganaCodes.encode latitude, longitude, area_fineness
38
+ ```
39
+ - Decoding
40
+
41
+ ```ruby
42
+ require 'hiragana_codes'
43
+ HiraganaCodes.decode code
44
+ ```
45
+
46
+ ### シェルコマンド
47
+ - Encoding
48
+
49
+ ```bash
50
+ $ hencode latitude, longitude, area_fineness
51
+ すらしうさけつるけえかけ
52
+ ```
53
+ - Decoding
54
+
55
+ ```bash
56
+ $ hdecode code
57
+ 34.7331654, 135.5002144
58
+ ```
59
+
60
+ ## 示す範囲
61
+ - 2桁(粒度0)
62
+ - 南北1000km, 東西500km
63
+ - 4桁(粒度1)
64
+ - 南北25km, 東西12.5km
65
+ - 6桁(粒度2)
66
+ - 南北625m, 東西312.5m
67
+ - 8桁(粒度3)
68
+ - 南北15.625m, 東西7.8125m
69
+ - 10桁(粒度4)
70
+ - 南北39.0625cm, 東西19.53125cm
71
+ - 12桁(粒度5)
72
+ - 南北9.765625mm, 東西4.8828125mm
73
+
74
+ ## ライセンス
75
+ [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hiragana_codes"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,6 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require "hiragana_codes"
4
+
5
+ code = ARGV[0].chomp
6
+ puts HiraganaCodes.decode code
@@ -0,0 +1,14 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require "hiragana_codes"
4
+
5
+ latitude = ARGV[0].to_f
6
+ if (0..90).include? latitude # 北極(N90)起点の緯度に変更
7
+ adjusted_latitude = 90 - latitude
8
+ elsif (-90..0).include? latitude
9
+ adjusted_latitude = latitude * -1 + 90
10
+ end
11
+
12
+ adjusted_longitude = ARGV[1].to_f + 180
13
+
14
+ puts HiraganaCodes.encode adjusted_latitude, adjusted_longitude, ARGV[2].to_i
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ require_relative './lib/hiragana_codes'
2
+
3
+ puts HiraganaCodes.coordinate_to_code 90 - ARGV[0].to_f, 180 + ARGV[1].to_f, ARGV[2].to_i
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hiragana_codes/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hiragana_codes"
8
+ spec.version = HiraganaCodes::VERSION
9
+ spec.authors = ["sei0o"]
10
+ spec.email = ["sei0o@live.jp", "sei0o@sei0o.xyz"]
11
+
12
+ spec.summary = "plus+codes in Japanese Hiragana"
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = "https://github.com/sei0o/hiraganaCodes"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,61 @@
1
+ require "hiragana_codes/version"
2
+
3
+ module HiraganaCodes
4
+ CHARACTERS = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもらりるれろ".split ""
5
+
6
+ def self.encode latitude, longitude, area_fineness = 4, next_area_fineness = 0 # 緯度、経度(N90, W180 を起点として)、変換後の細かさ(0で最大)、次に変換するときの細かさ
7
+ return if area_fineness < next_area_fineness
8
+
9
+ latitude_code = CHARACTERS[(latitude / latitude_per_character(next_area_fineness)).floor]
10
+ longitude_code = CHARACTERS[(longitude / longitude_per_character(next_area_fineness)).floor]
11
+
12
+ return latitude_code + longitude_code if area_fineness == next_area_fineness # 「変換後の細かさ」に達したら
13
+
14
+ relative_latitude = latitude - area_westmost(latitude, next_area_fineness) # 次に変換するときはcodeの示す緯度経度の最西・最北端を起点として変換する
15
+ relative_longitude = longitude - area_northmost(longitude, next_area_fineness)
16
+
17
+ latitude_code + longitude_code + encode(relative_latitude, relative_longitude, area_fineness, next_area_fineness + 1)
18
+ end
19
+
20
+ def self.decode code
21
+ return if code.size.odd?
22
+
23
+ area_westmost = area_eastmost = area_northmost = area_southmost = 0
24
+ areas = code.scan(/.{2}/)
25
+
26
+ areas.each_with_index do |area, fineness|
27
+ area_westmost += CHARACTERS.index(area[0]) * latitude_per_character(fineness) # どんどん足していく
28
+ area_eastmost += (CHARACTERS.index(area[0]) + 1) * latitude_per_character(fineness) # +1 で次の地区の緯度経度がとれる
29
+ area_northmost += CHARACTERS.index(area[1]) * longitude_per_character(fineness)
30
+ area_southmost += (CHARACTERS.index(area[1]) + 1) * longitude_per_character(fineness)
31
+ end
32
+
33
+ [area_westmost, area_eastmost, area_northmost, area_southmost]
34
+ end
35
+
36
+ def self.area_westmost latitude, area_fineness = 0 # 緯度経度の属するareaの最西端
37
+ # latitudeが42度のとき、latitude_per_character(area_fineness)が10とすると、
38
+ # (latitude / latitude_per_character(area_fineness)) は4.2、floorして4になるから、
39
+ # その地点の左に4地区あるということになる。
40
+ # その4に、latitude_per_character(area_fineness)をかけて 40、areaの最西端が分かる
41
+ (latitude / latitude_per_character(area_fineness)).floor * latitude_per_character(area_fineness)
42
+ end
43
+
44
+ def self.area_northmost longitude, area_fineness = 0 # 緯度経度の属するareaの最北端
45
+ (longitude / longitude_per_character(area_fineness)).floor * longitude_per_character(area_fineness)
46
+ end
47
+
48
+ def self.latitude_per_character area_fineness = 0 # 1文字ごとに割り当てる緯度
49
+ degree = 180
50
+ (area_fineness + 1).times { degree /= CHARACTERS.size.to_f } # area_finenessが0なら一回, 1なら二回, 地区を分割する
51
+
52
+ degree
53
+ end
54
+
55
+ def self.longitude_per_character area_fineness = 0 # 1文字ごとに割り当てる経度
56
+ degree = 360
57
+ (area_fineness + 1).times { degree /= CHARACTERS.size.to_f }
58
+
59
+ degree
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module HiraganaCodes
2
+ VERSION = "0.1.2"
3
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hiragana_codes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - sei0o
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - sei0o@live.jp
44
+ - sei0o@sei0o.xyz
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/hdecode
56
+ - bin/hencode
57
+ - bin/setup
58
+ - example.rb
59
+ - hiragana_codes.gemspec
60
+ - lib/hiragana_codes.rb
61
+ - lib/hiragana_codes/version.rb
62
+ homepage: https://github.com/sei0o/hiraganaCodes
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.5.1
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: plus+codes in Japanese Hiragana
86
+ test_files: []