Project

thai_units

0.0
The project is in a healthy, maintained state
A Ruby gem that provides a converter for Thai-specific units — like rai, ngan, wah, and baht (gold) — to metric units such as square meters and grams. Ideal for real estate, finance, and Thai government applications.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 0
 Project Readme

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.