Sha256: 381d098f0bdf66612cbd0760eb2c92011669567ddd5401faf90ddb1eac69a322

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

# FormattedLength [![Build Status](https://secure.travis-ci.org/mrnbrkt/formatted_length.png)](http://travis-ci.org/mrnbrkt/formatted_length)


## Description
Gem allows auto-formatting to/from string to time span (integer value of seconds). 
It does so by adding an *acts_as_formatted_length* method to ActiveRecord base classes. 

## Installation
Simply add this row to your Gemfile

```ruby
gem 'formatted_length'
```

## Usage
Once *acts_as_formatted_length* is added to class definition, a _formatted_length_ property becomes available, 
which is a string representation of the number of seconds by default saved in the class :length field.

If you want to use a different field, for instance - :foobar, use:

```ruby
#sample class definition
class YourClass
#implementation etc...
acts_as_formatted_length :foobar
end

#now usage
example = YourClass.create(foobar: 70)
puts example.formatted_length # prints out 01:10
example.formatted_length = "1:01:06"
puts example.foobar  # prints out 3666
```

## Example
|Integer value|String Representation|
|:----:|:-----------:|
|0|00:00|
|10|00:10|
|70|01:10|
|3666|1:01:06|

## License
Project uses MIT-LICENSE. 

## Contribution
Feel free, by all means! 

1. Fork
2. Fix
3. Rebase
4. Push
5. File pull request

Cheers,

Meron Bareket

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
formatted_length-0.0.7 README.md