Skip to content

Commit

Permalink
README update
Browse files Browse the repository at this point in the history
  • Loading branch information
dreymonde committed Apr 11, 2016
1 parent d20306c commit 3a9a4c6
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# InterchangeDataMapper
# StructuredDataMapper
[![Zewo 0.4][zewo-badge]](http://zewo.io)
[![Swift 3][swift-badge]](https://swift.org)
[![Platform Linux][platforms-badge]](https://swift.org)
[![License MIT][mit-badge]](https://tldrlegal.com/license/mit-license)
[![Codebeat][codebeat-badge]](https://codebeat.co/projects/github-com-zewo-interchangedatamapper)

**InterchangeDataMapper** is a tiny and simple library which allows you to convert Zewo's `InterchangeData` to strongly typed objects. Deeply inspired by Lyft's [Mapper][mapper-url].
**StructuredDataMapper** is a tiny and simple library which allows you to convert Zewo's `StructuredData` to strongly typed objects. Deeply inspired by Lyft's [Mapper][mapper-url].

## Usage
#### Simplest example:

``` swift
import InterchangeDataMapper
import StructuredDataMapper

struct User: Mappable {
let id: Int
Expand All @@ -26,12 +26,12 @@ struct User: Mappable {
}
}

let content: InterchangeData = [
let content: StructuredData = [
"id": 1654,
"username": "fireringer",
"city": "Houston"
]
let user = User.makeWith(interchangeData: content) // User?
let user = User.makeWith(structuredData: content) // User?
```

#### Mapping arrays
Expand All @@ -56,7 +56,7 @@ struct Album: Mappable {
```

#### Mapping enums
You can use **InterchangeDataMapper** for mapping enums with raw values. Right now you can use only `String`, `Int` and `Double` as raw value.
You can use **StructuredDataMapper** for mapping enums with raw values. Right now you can use only `String`, `Int` and `Double` as raw value.

```swift
enum GuitarType: String {
Expand Down Expand Up @@ -95,12 +95,12 @@ struct Club: Mappable {
}
```

#### Using `InterchangeDataInitializable`
`Mappable` is great for complex entities, but for the simplest one you can use `InterchangeDataInitializable` protocol. `InterchangeDataInitializable` objects can be initializaed from `InterchangeData` itself, not from its `Mapper`. For example, **InterchangeDataMapper** uses `InterchangeDataInitializable` to allow seamless `Int` conversion:
#### Using `StructuredDataInitializable`
`Mappable` is great for complex entities, but for the simplest one you can use `StructuredDataInitializable` protocol. `StructuredDataInitializable` objects can be initializaed from `StructuredData` itself, not from its `Mapper`. For example, **StructuredDataMapper** uses `StructuredDataInitializable` to allow seamless `Int` conversion:

```swift
extension Int: InterchangeDataInitializable {
public init(interchangeData value: InterchangeData) throws {
extension Int: StructuredDataInitializable {
public init(structuredData value: StructuredData) throws {
switch value {
case .numberValue(let number):
self.init(number)
Expand All @@ -122,14 +122,14 @@ struct Generation: Mappable {
}
```

Conversion of `Int` is available in **InterchangeDataMapper** out of the box, and you can extend any other type to conform to `InterchangeDataInitializable` yourself, for example, `NSDate`:
Conversion of `Int` is available in **StructuredDataMapper** out of the box, and you can extend any other type to conform to `StructuredDataInitializable` yourself, for example, `NSDate`:

```swift
import Foundation
import InterchangeDataMapper
import StructuredDataMapper

extension InterchangeDataInitializable where Self: NSDate {
public init(interchangeData value: InterchangeData) throws {
extension StructuredDataInitializable where Self: NSDate {
public init(structuredData value: StructuredData) throws {
switch value {
case .numberValue(let number):
self.init(timeIntervalSince1970: number)
Expand All @@ -138,11 +138,11 @@ extension InterchangeDataInitializable where Self: NSDate {
}
}
}
extension NSDate: InterchangeDataInitializable { }
extension NSDate: StructuredDataInitializable { }
```

## Installation
- Add `InterchangeDataMapper` to your `Package.swift`
- Add `StructuredDataMapper` to your `Package.swift`

```swift
import PackageDescription
Expand All @@ -154,7 +154,7 @@ let package = Package(
)
```

**InterchangeDataMapper** (as *Topo*) is also available for [Zewo 0.3][topo-0.3].
**StructuredDataMapper** (as *Topo*) is also available for [Zewo 0.3][topo-0.3].

## See also
[Resource][resource-url], which provides RESTful resources for Zewo's Router.
Expand All @@ -166,15 +166,15 @@ let package = Package(
Join us on [Slack](http://slack.zewo.io).

## License
**InterchangeDataMapper** is released under the MIT license. See LICENSE for details.
**StructuredDataMapper** is released under the MIT license. See LICENSE for details.

[zewo-badge]: https://img.shields.io/badge/Zewo-0.4-FF7565.svg?style=flat
[swift-badge]: https://img.shields.io/badge/Swift-3.0-orange.svg?style=flat
[mapper-url]: https://github.com/lyft/mapper
[interchange-data-url]: https://github.com/Zewo/InterchangeData
[interchange-data-url]: https://github.com/Zewo/StructuredData
[resource-url]: https://github.com/paulofaria/Resource
[cont-neg-mid-url]: https://github.com/Zewo/ContentNegotiationMiddleware
[mit-badge]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat
[platforms-badge]: https://img.shields.io/badge/Platform-Linux-lightgray.svg?style=flat
[topo-0.3]: https://github.com/Zewo/Topo/tree/zewo0.3
[codebeat-badge]: https://codebeat.co/badges/67df5828-b0d3-4d73-a587-3b994d6aaf1f
[codebeat-badge]: https://codebeat.co/badges/67df5828-b0d3-4d73-a587-3b994d6aaf1fStructuredData

0 comments on commit 3a9a4c6

Please sign in to comment.