K Util
KUtil provides simple utility methods
Installation
Add this line to your application's Gemfile:
gem 'k_util'
And then execute:
bundle install
Or install it yourself as:
gem install k_util
Stories
Main Story
As a Developer, I need simple utility helpers, to solve cross cutting issues and simplify common access methods
See all stories
Usage
See all usage examples
Basic Example
Console Helpers
Generate encoded strings that have meaning in the console
puts KUtil.console.hyperlink('Google', 'https://google.com')
# "Google"
# (clickable hyperlink to the google website)
puts KUtil.console.file_hyperlink('My File', '/somepath/my-file.txt')
# "My File"
# (clickable link to the a file in the file system)
Data Helpers
Data object helpers such as any object to open struct and any object to hash
ThunderBirds = Struct.new(:action)
virgil =
OpenStruct.new(
name: 'Virgil Tracy', age: 73, thunder_bird: ThunderBirds.new(:are_grounded)
)
penny =
OpenStruct.new(
name: 'Lady Penelope', age: 69, thunder_bird: ThunderBirds.new(:are_go)
)
data = {
key1: 'David',
key2: 333,
key3: ThunderBirds.new(:are_go),
people: [virgil, penny]
}
data_open = KUtil.data.to_open_struct(data)
data_hash = KUtil.data.to_hash(data_open)
puts JSON.pretty_generate(data_hash)
# {
# "key1": "David",
# "key2": 333,
# "key3": {
# "action": "are_go"
# },
# "people": [
# {
# "name": "Virgil Tracy",
# "age": 73,
# "thunder_bird": {
# "action": "are_grounded"
# }
# },
# {
# "name": "Lady Penelope",
# "age": 69,
# "thunder_bird": {
# "action": "are_go"
# }
# }
# ]
# }
File Helpers
puts KUtil.file.('file.rb')
# /current/folder/file.rb
puts KUtil.file.('/file.rb')
# /file.rb
puts KUtil.file.('~/file.rb')
# /Users/current-user/file.rb
puts KUtil.file.('file.rb', '/klue-less/xyz')
# /klue-less/xyz/file.rb
puts KUtil.file.pathname_absolute?('somepath/somefile.rb')
# false
puts KUtil.file.pathname_absolute?('/somepath/somefile.rb')
# true
Development
Checkout the repo
git clone klueless-io/k_util
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests.
You can also run bin/console
for an interactive prompt that will allow you to experiment.
bin/console
Aaa::Bbb::Program.execute()
# => ""
k_util
is setup with Guard, run guard
, this will watch development file changes and run tests automatically, if successful, it will then run rubocop for style quality.
To release a new version, update the version number in version.rb
, build the gem and push the .gem
file to rubygems.org.
rake publish
rake clean
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/klueless-io/k_util. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the K Util project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
Copyright
Copyright (c) David Cruwys. See MIT License for further details.