linked 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8501da277d54cd430b7caec75a20df3670cf0a7
4
- data.tar.gz: f027fcee69636bd7c3cef7a9b1d34d54d69d104e
3
+ metadata.gz: d85491962a16ae84236a5e278940ba46b6b29c65
4
+ data.tar.gz: 97acd2defdcb3d1a983a29582daaadf3019ca317
5
5
  SHA512:
6
- metadata.gz: 8699f64f9331749e745ed4f793f1cc9b372459ac2c6644cc34dee7ae8baf8150682c19934a9017dc03fc3cd50da3f2806631c38301b8627340afa20a0d37fd55
7
- data.tar.gz: a70747dae1d050e30229393e2df5cc8fc0075ae29fcb969233772083447e1071bcd179243ab1f5ce64bb45e77c35efe4e446cd608919407b68e465f8ce2b7bfe
6
+ metadata.gz: 5f8fc6b24885ac1d7f66b7bbf273bf4744bc765f41b33b6ca71c41e4dc5d3ad0f8cdd37976b2730a79594661d93d6a77dba43155c2e2f8def5b42b650b99c28e
7
+ data.tar.gz: fb1a283dfa52704de58e93843a5fedefa86275f2b5be514575f3baef1a3610caacbbbefeba49373257e4863215464a4f57273619898e8a0ec22029f44eb995e1
data/lib/linked/item.rb CHANGED
@@ -24,7 +24,7 @@ module Linked
24
24
  #
25
25
  # Returns the item's list, or nil
26
26
 
27
- attr_accessor :list
27
+ attr_writer :list
28
28
  protected :list=
29
29
 
30
30
  # The Item can hold an arbitrary object as its value and it will stay with
@@ -71,6 +71,36 @@ module Linked
71
71
  end
72
72
  super
73
73
  end
74
+
75
+ # Identity method that simply return the item. This method mirrors List#item
76
+ # and allows other methods that work on Item objects to easily and
77
+ # interchangebly accept both lists and items as arguments.
78
+ #
79
+ # Returns the item itself.
80
+
81
+ def item
82
+ self
83
+ end
84
+
85
+ # Access the list that the item is part of. If the item is not in a list a
86
+ # NoMethodError will be raised. This mirrors the behaviour of List#list and
87
+ # allows other methods that work on List objects to easily and
88
+ # interchangeably accept both lists and items as arguments.
89
+ #
90
+ # Returns the list that the item is part of.
91
+
92
+ def list
93
+ raise NoMethodError unless @list
94
+ @list
95
+ end
96
+
97
+ # Check it the item is part of a list.
98
+ #
99
+ # Returns true if the item is in a list.
100
+
101
+ def in_list?
102
+ @list ? true : false
103
+ end
74
104
 
75
105
  # Check if this is the first item in the list. It is crucial that tail#nil?
76
106
  # returns true for the first item to be identified correctly.
data/lib/linked/list.rb CHANGED
@@ -62,6 +62,28 @@ module Linked
62
62
 
63
63
  super
64
64
  end
65
+
66
+ # Identity method that simply return the list. This method mirrors Item#list
67
+ # and allows other methods that work on List objects to easily and
68
+ # interchangebly accept both lists and items as arguments.
69
+ #
70
+ # Returns the list itself.
71
+
72
+ def list
73
+ self
74
+ end
75
+
76
+ # Access the first item in the list. If the list is empty a NoMethodError
77
+ # will be raised. This mirrors the behaviour of Item#item and allows other
78
+ # methods that work on List objects to easily and interchangeably accept
79
+ # both lists and items as arguments.
80
+ #
81
+ # Returns the first item in the list.
82
+
83
+ def item
84
+ raise NoMethodError if empty?
85
+ eol.next
86
+ end
65
87
 
66
88
  # Access the first n item(s) in the list. If a block is given each item will
67
89
  # be yielded to it. The first item, starting from the first in the list, for
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Linked
4
- VERSION = '0.1.3'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linked
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Lindberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-08 00:00:00.000000000 Z
11
+ date: 2016-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler