Thai Units
A Ruby converter for traditional Thai measurement units — land (ไร่, งาน, ตารางวา) and gold weight (บาท, สลึง) — into metric units like square meters and grams.
Ideal for real estate, finance, e-commerce, and Thai government applications.
🔁 แปลงหน่วยวัดไทย เช่น ไร่ งาน ตารางวา และ บาททองคำ เป็นตารางเมตร กรัม และออนซ์ทองคำ
Installation
Add this line to your Gemfile:
gem 'thai_units'
Or install it directly:
gem install thai_units
Usage
require 'thai_units'
🏡 Land Area Conversion
# Convert from rai-ngan-wah to square meters
ThaiUnits::Land.to_sqm(rai: 1, ngan: 2, wah: 50)
# => 1000.0
# Convert from square meters to rai-ngan-wah
ThaiUnits::Land.from_sqm(2640)
# => { rai: 1, ngan: 2, wah: 10 }
🪙 Gold Weight Conversion
# Convert Thai gold weight (baht & salueng) to grams
ThaiUnits::Gold.to_grams(baht: 2, salueng: 2)
# => 38.055
# Convert grams to Thai gold weight units
ThaiUnits::Gold.from_grams(45.732)
# => { baht: 3, salueng: 0 }
✍️ Land Area String Formatter
# Format land area hash to string
ThaiUnits::Formatter.format_land({ rai: 2, ngan: 3, wah: 15 })
# => "2-3-15"
# Parse formatted string to land hash
ThaiUnits::Formatter.parse_land("2-3-15")
# => { rai: 2, ngan: 3, wah: 15 }
Development
Run tests with:
bundle exec rspec
License
This gem is licensed under the MIT License.