thai_units 0.1.0
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.
- checksums.yaml +7 -0
- data/README.md +89 -0
- data/lib/thai_units/formatter.rb +20 -0
- data/lib/thai_units/gold.rb +21 -0
- data/lib/thai_units/land.rb +19 -0
- data/lib/thai_units/version.rb +5 -0
- data/lib/thai_units.rb +9 -0
- metadata +65 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9cba2832e33e85f8e6e10b61616be9958dc9f7fa3a75ad752817d5d31d4681b8
|
|
4
|
+
data.tar.gz: 4b4e92009a67dead185dca654e11c0bedf0e3d003e4eefa649f8c49ffffdee90
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3528ba493d611dbc0e10c8d11321456a9ef21a02fbb25dff1259881251c97daaa10075e28b21bcff2803ba2ea1082f4fd71d3183e5e3e58fc1c252745ea01854
|
|
7
|
+
data.tar.gz: 38875d2c8bd0e8ee2706017c3c32ae42363f52481b04e533092d101ae6fce3122303ff15131d7530a35289eb25429665c9ab7cd86828d7e114cc176887ba7723
|
data/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Thai Units
|
|
2
|
+
|
|
3
|
+
A Ruby converter for traditional Thai measurement units — land (ไร่, งาน, ตารางวา) and gold weight (บาท, สลึง) — into metric units like square meters and grams.
|
|
4
|
+
Ideal for real estate, finance, e-commerce, and Thai government applications.
|
|
5
|
+
|
|
6
|
+
🔁 แปลงหน่วยวัดไทย เช่น ไร่ งาน ตารางวา และ บาททองคำ เป็นตารางเมตร กรัม และออนซ์ทองคำ
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Add this line to your Gemfile:
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
gem 'thai_units'
|
|
16
|
+
````
|
|
17
|
+
|
|
18
|
+
Or install it directly:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
gem install thai_units
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
require 'thai_units'
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
### 🏡 Land Area Conversion
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
# Convert from rai-ngan-wah to square meters
|
|
38
|
+
ThaiUnits::Land.to_sqm(rai: 1, ngan: 2, wah: 50)
|
|
39
|
+
# => 1000.0
|
|
40
|
+
|
|
41
|
+
# Convert from square meters to rai-ngan-wah
|
|
42
|
+
ThaiUnits::Land.from_sqm(2640)
|
|
43
|
+
# => { rai: 1, ngan: 2, wah: 10 }
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
### 🪙 Gold Weight Conversion
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
# Convert Thai gold weight (baht & salueng) to grams
|
|
52
|
+
ThaiUnits::Gold.to_grams(baht: 2, salueng: 2)
|
|
53
|
+
# => 38.055
|
|
54
|
+
|
|
55
|
+
# Convert grams to Thai gold weight units
|
|
56
|
+
ThaiUnits::Gold.from_grams(45.732)
|
|
57
|
+
# => { baht: 3, salueng: 0 }
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### ✍️ Land Area String Formatter
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
# Format land area hash to string
|
|
66
|
+
ThaiUnits::Formatter.format_land({ rai: 2, ngan: 3, wah: 15 })
|
|
67
|
+
# => "2-3-15"
|
|
68
|
+
|
|
69
|
+
# Parse formatted string to land hash
|
|
70
|
+
ThaiUnits::Formatter.parse_land("2-3-15")
|
|
71
|
+
# => { rai: 2, ngan: 3, wah: 15 }
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Development
|
|
77
|
+
|
|
78
|
+
Run tests with:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
bundle exec rspec
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
This gem is licensed under the [MIT License](LICENSE.txt).
|
|
89
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ThaiUnits
|
|
4
|
+
# ThaiUnits::Formatter handles parsing and formatting of Thai land unit strings,
|
|
5
|
+
# such as converting "2-3-15" into a hash or formatting a hash into a land string.
|
|
6
|
+
class Formatter
|
|
7
|
+
# Parses a formatted string like "2-3-15" to a hash { rai:, ngan:, wah: }
|
|
8
|
+
def self.parse_land(str)
|
|
9
|
+
parts = str.strip.split('-').map(&:to_i)
|
|
10
|
+
raise ArgumentError, 'Invalid format' unless parts.size == 3
|
|
11
|
+
|
|
12
|
+
{ rai: parts[0], ngan: parts[1], wah: parts[2] }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Formats a land hash like { rai: 2, ngan: 3, wah: 15 } to "2-3-15"
|
|
16
|
+
def self.format_land(land_hash)
|
|
17
|
+
"#{land_hash[:rai]}-#{land_hash[:ngan]}-#{land_hash[:wah]}"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ThaiUnits
|
|
4
|
+
# ThaiUnits::Gold provides methods for converting Thai gold weight units
|
|
5
|
+
# such as baht and salueng to and from grams.
|
|
6
|
+
class Gold
|
|
7
|
+
BAHT_TO_GRAMS = 15.244
|
|
8
|
+
SALUENG_TO_GRAMS = BAHT_TO_GRAMS / 4
|
|
9
|
+
TROY_OUNCE_IN_GRAMS = 31.1035
|
|
10
|
+
|
|
11
|
+
def self.to_grams(baht: 0, salueng: 0)
|
|
12
|
+
(baht * BAHT_TO_GRAMS) + (salueng * SALUENG_TO_GRAMS)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.from_grams(grams)
|
|
16
|
+
baht = grams / BAHT_TO_GRAMS
|
|
17
|
+
salueng = (grams % BAHT_TO_GRAMS) / SALUENG_TO_GRAMS
|
|
18
|
+
{ baht: baht.floor, salueng: salueng.floor }
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ThaiUnits
|
|
4
|
+
# ThaiUnits::Land provides methods for converting Thai land area units
|
|
5
|
+
# such as rai, ngan, and square wah to and from square meters.
|
|
6
|
+
class Land
|
|
7
|
+
def self.to_sqm(rai: 0, ngan: 0, wah: 0)
|
|
8
|
+
(rai * 1600) + (ngan * 400) + (wah * 4)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.from_sqm(sqm)
|
|
12
|
+
rai = sqm / 1600
|
|
13
|
+
remainder = sqm % 1600
|
|
14
|
+
ngan = remainder / 400
|
|
15
|
+
wah = (remainder % 400) / 4
|
|
16
|
+
{ rai: rai.floor, ngan: ngan.floor, wah: wah.floor }
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/thai_units.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: thai_units
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Chayut Orapinpatipat
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-06-16 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
description: A Ruby gem that provides a converter for Thai-specific units — like rai,
|
|
28
|
+
ngan, wah, and baht (gold) — to metric units such as square meters and grams. Ideal
|
|
29
|
+
for real estate, finance, and Thai government applications.
|
|
30
|
+
email:
|
|
31
|
+
- chayut_o@hotmail.com
|
|
32
|
+
executables: []
|
|
33
|
+
extensions: []
|
|
34
|
+
extra_rdoc_files: []
|
|
35
|
+
files:
|
|
36
|
+
- README.md
|
|
37
|
+
- lib/thai_units.rb
|
|
38
|
+
- lib/thai_units/formatter.rb
|
|
39
|
+
- lib/thai_units/gold.rb
|
|
40
|
+
- lib/thai_units/land.rb
|
|
41
|
+
- lib/thai_units/version.rb
|
|
42
|
+
homepage: https://github.com/chayuto/thai_units
|
|
43
|
+
licenses:
|
|
44
|
+
- MIT
|
|
45
|
+
metadata: {}
|
|
46
|
+
post_install_message:
|
|
47
|
+
rdoc_options: []
|
|
48
|
+
require_paths:
|
|
49
|
+
- lib
|
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '0'
|
|
60
|
+
requirements: []
|
|
61
|
+
rubygems_version: 3.5.11
|
|
62
|
+
signing_key:
|
|
63
|
+
specification_version: 4
|
|
64
|
+
summary: Converter for traditional Thai units (land, gold) to metric and more.
|
|
65
|
+
test_files: []
|